import { Command } from 'discord-akairo'; import { Message } from 'discord.js'; import { TextChannel } from 'discord.js'; export default class SlowmodeMod extends Command { public constructor() { super('slowmode', { aliases: ['slowmode', 'slow', 'cooldown'], category: 'moderation', description: { content: 'Add a specified amount of slowmode to the current channel.', usage: '[amount 1-120] [time slowmode should be active for]', examples: [ '5 60' ] }, ratelimit: 3, channel: 'guild', clientPermissions: ['MANAGE_CHANNELS'], userPermissions: ['MANAGE_CHANNELS'], args: [ { id: 'amount', type: 'integer', prompt: { start: 'What amount of slowmode would you like to add to the channel?' } }, { id: 'realtime', type: 'integer', prompt: { start: 'How long would you like the slowmode to last?', optional: true } } ] }); } public exec(msg: Message, { amount, realtime }): Promise { try { if (amount > 120) { amount = 120; msg.channel.send('Due to Discord API limitations, slow mode can only be a max of **120** seconds or less! Your specified amount has been rounded down to **120** seconds. (This message will automatically be deleted in 10 seconds.)') .then(m => m.delete({ timeout: 10000 })); } (msg.channel as TextChannel).setRateLimitPerUser(amount); if (realtime) { let time = 60000 * realtime; msg.channel.send(`Slowmode has now been set to **${amount}** seconds and will end in **${realtime}** minutes!`); setTimeout(() => { (msg.channel as TextChannel).setRateLimitPerUser(0); return msg.channel.send('Slowmode has now been disabled!'); }, time); } else { if (amount == 0) return msg.channel.send('Slowmode has now been disabled!'); return msg.channel.send(`Slowmode has now been set to **${amount}** seconds!`); } } catch (err) { console.error(err); } } }