Allows an admin role to set a channel's rate limit to some number in seconds (enable slowmode). Run with no parameters to clear the rate limit.
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
let ADMIN_ROLE = 'YOUR_ADMIN_ROLE_HERE';
if (context.params.event.content.startsWith(`!ratelimit`)) {
if (context.params.event.member.roles.includes(ADMIN_ROLE)) {
let rateLimit = context.params.event.content.split(' ')[1];
await lib.discord.channels['@0.1.1'].update({
channel_id: context.params.event.channel_id,
rate_limit_per_user: parseInt(rateLimit) || 0
});
await lib.discord.channels['@0.1.1'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `<@!${context.params.event.author.id}> changed this channel's rate limit to ${rateLimit}!`
});
} else {
await lib.discord.channels['@0.1.1'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `Sorry <@!${context.params.event.author.id}>, you don't have permission to change the rate limit.`
});
}
}