Created
March 22, 2020 21:03
-
-
Save TotallyNotNero/e496d34f21e86a26009f485d144d437b to your computer and use it in GitHub Desktop.
Slowmode for an advanced discord bot.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Discord = require('discord.js'); | |
const fs = require('fs'); | |
const colors = require('colors'); | |
const math = require('mathjs'); | |
module.exports = { | |
name: 'slowmode', | |
aliases: ['sl', 'sm'], | |
description: 'Set the slowmode for a channel', | |
module: 'moderator', | |
use: `slowmode <time in seconds/off>`, | |
ownerOnly: false, | |
guildOnly: false, | |
silent: true, | |
premium: false, | |
cost: 0, | |
cooldown: 0, | |
async run(client, message, args, _guilds, _userGuild, _users) { | |
if (!message.member.hasPermission('MANAGE_CHANNELS')) { | |
let noPermsEmbed = new Discord.RichEmbed() | |
.setAuthor(message.author.tag, message.author.avatarURL) | |
.setDescription(`You do not have the required permissions to use this command`) | |
.setColor('ff0000') | |
.setFooter(`ERROR`) | |
.setTimestamp(); | |
if (_guilds.settings.noPermsMessage == true) { | |
if (_guilds.settings.useEmbeds == true) return message.channel.send(noPermsEmbed); | |
else return message.channel.send(`You do not have the required permissions to use this command, ${message.author}`); | |
} else return; | |
} | |
if (!message.guild.me.hasPermission('MANAGE_CHANNELS')) { | |
let noBotPermsEmbed = new Discord.RichEmbed() | |
.setAuthor(message.author.tag, message.author.avatarURL) | |
.setDescription(`I do not have the required permissions for this command to be executed`) | |
.setColor('ff0000') | |
.setFooter(`ERROR`) | |
.setTimestamp(); | |
if (_guilds.settings.useEmbeds == true) return message.channel.send(noBotPermsEmbed); | |
else return message.channel.send(`I do not have the required permissions for this command to be executed, ${message.author}`); | |
} | |
if (message.guild.me.hasPermission('MANAGE_MESSAGES')) | |
if (this.silent == true) message.delete().catch(); | |
if (args[0] == 'off' || args[0] == '0') { | |
message.channel.setRateLimitPerUser(0, `none`).catch(); | |
let turnedOffEmbed = new Discord.RichEmbed() | |
.setAuthor(message.author.tag, message.author.avatarURL) | |
.setDescription(`Channel Slowmode disabled`) | |
.setColor(message.member.displayHexColor) | |
.setFooter(`Slowmode`) | |
.setTimestamp(); | |
if (_guilds.settings.useEmbeds == true) return message.channel.send(turnedOffEmbed); | |
else return message.channel.send(`Channel Slowmode disabled, ${message.author}`); | |
} | |
if (isNaN(args[0])) { | |
let isNanEmbed = new Discord.RichEmbed() | |
.setAuthor(message.author.tag, message.author.avatarURL) | |
.setDescription(`You must include a number as the delay`) | |
.setColor(message.member.displayHexColor) | |
.setFooter(`Slowmode`) | |
.setTimestamp(); | |
if (_guilds.settings.useEmbeds == true) return message.channel.send(isNanEmbed); | |
else return message.channel.send(`You must include a number as the delay, ${message.author}`); | |
} | |
let time = math.round(args[0]); | |
if (time < 1 || time > 21600) { | |
let notAcceptableValueEmbed = new Discord.RichEmbed() | |
.setAuthor(message.author.tag, message.author.avatarURL) | |
.setDescription(`The rate must be greater than 0 but less than 21,600`) | |
.setColor(message.member.displayHexColor) | |
.setFooter(`Slowmode`) | |
.setTimestamp(); | |
if (_guilds.settings.useEmbeds == true) return message.channel.send(notAcceptableValueEmbed); | |
else return message.channel.send(`The rate must be greater than 0 but less than 21,600, ${message.author}`); | |
} | |
message.channel.setRateLimitPerUser(time, `none`).catch(); | |
let changedSlowModeEmbed = new Discord.RichEmbed() | |
.setAuthor(message.author.tag, message.author.avatarURL) | |
.setDescription(`Slowmode set to ${time} seconds`) | |
.setColor(message.member.displayHexColor) | |
.setFooter(`Slowmode`) | |
.setTimestamp(); | |
if (_guilds.settings.useEmbeds == true) return message.channel.send(changedSlowModeEmbed); | |
else return message.channel.send(`Slowmode set to ${time} seconds, ${message.author}`); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment