import { BushCommand, type BushMessage, type BushNewsChannel, type BushSlashMessage, type BushTextChannel, type BushThreadChannel } from '#lib'; import { Argument } from 'discord-akairo'; import { TextChannel, ThreadChannel, type NewsChannel } from 'discord.js'; export default class SlowModeCommand extends BushCommand { public constructor() { super('slowmode', { aliases: ['slowmode', 'slow'], category: 'moderation', description: 'A command to set the slowmode of a channel.', usage: ['slowmode [channel]'], examples: ['slowmode 3'], args: [ { id: 'length', description: 'The amount of time to set the slowmode of a channel to.', type: Argument.union('duration', 'durationSeconds', 'off', 'none', 'disable'), readableType: "duration|durationSeconds|'off'|'none'|'disable'", prompt: 'What would you like to set the slowmode to?', retry: '{error} Please set the slowmode to a valid length.', optional: true, slashType: 'INTEGER' }, { id: 'channel', description: 'The channel to change the slowmode of, defaults to the current channel.', type: 'channel', prompt: 'What channel would you like to change?', retry: '{error} Choose a valid channel.', optional: true, slashType: 'CHANNEL', channelTypes: ['GUILD_TEXT', 'GUILD_PRIVATE_THREAD', 'GUILD_PUBLIC_THREAD'] } ], slash: true, channel: 'guild', clientPermissions: (m) => util.clientSendAndPermCheck(m, ['MANAGE_CHANNELS', 'EMBED_LINKS'], true), userPermissions: (m) => util.userGuildPermCheck(m, ['MANAGE_MESSAGES']) }); } public override async exec( message: BushMessage | BushSlashMessage, { length, channel }: { length: number | 'off' | 'none' | 'disable' | null; channel: TextChannel | ThreadChannel | BushTextChannel | BushNewsChannel | BushThreadChannel | NewsChannel; } ) { if (message.channel!.type === 'DM') return await message.util.reply(`${util.emojis.error} This command cannot be run in dms.`); if (!channel) channel = message.channel as any; if (!(['GUILD_TEXT', 'GUILD_PRIVATE_THREAD', 'GUILD_PUBLIC_THREAD'] as const).includes(channel.type)) return await message.util.reply(`${util.emojis.error} <#${channel.id}> is not a text or thread channel.`); if (length) { length = typeof length === 'string' && !(['off', 'none', 'disable'] as const).includes(length) ? await util.arg.cast('duration', message, length) : length; } const length2: number = (['off', 'none', 'disable'] as const).includes(length as string) ? 0 : (length as number); const setSlowmode = await (channel as ThreadChannel | TextChannel) .setRateLimitPerUser(length2 / 1000, `Changed by ${message.author.tag} (${message.author.id}).`) .catch(() => {}); if (!setSlowmode) return await message.util.reply( `${util.emojis.error} There was an error changing the slowmode of <#${(channel as ThreadChannel | TextChannel).id}>.` ); else return await message.util.reply( `${util.emojis.success} Successfully changed the slowmode of <#${channel.id}> ${ length2 ? `to \`${util.humanizeDuration(length2)}` : '`off' }\`.` ); } }