-
Notifications
You must be signed in to change notification settings - Fork 59
/
slowmodeCommand.ts
55 lines (49 loc) · 1.56 KB
/
slowmodeCommand.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import {
ApplicationCommandOptionType,
ApplicationCommandType,
ChannelType,
PermissionsBitField,
TextChannel,
} from 'discord.js'
import { defineCommand } from '@/types/defineCommand'
export const slowmodeCommand = defineCommand({
data: {
name: 'slowmode',
description: 'Set slowmode for all text channels in the server',
defaultMemberPermissions:
PermissionsBitField.Flags.ManageChannels |
PermissionsBitField.Flags.ManageMessages,
type: ApplicationCommandType.ChatInput,
options: [
{
name: 'duration',
description: 'Duration of slowmode in seconds',
type: ApplicationCommandOptionType.Integer,
required: true,
min_value: 0,
max_value: 21_600, // 6 hours (discord limit)
},
],
},
ephemeral: true,
execute: async (botContext, interaction) => {
if (!interaction.guild || !interaction.isChatInputCommand()) return
// Get only text channels in the server
const channels = interaction.guild.channels.cache.filter(
(channel) => channel.type === ChannelType.GuildText,
)
// Get duration from the interaction
const duration = interaction.options.getInteger('duration')
// Set slowmode for all channels
await Promise.all(
channels.map(async (channel) => {
const textChannel = channel as TextChannel
await textChannel.setRateLimitPerUser(duration ?? 0)
}),
)
// Send confirmation message
await interaction.editReply({
content: `Slowmode set to ${duration} seconds for all text channels`,
})
},
})