JaBa/commands/Administration/slowmode.js

54 lines
1.7 KiB
JavaScript
Raw Normal View History

2021-12-10 21:39:54 +05:00
const Command = require("../../base/Command.js"),
ms = require("ms");
class Slowmode extends Command {
2021-12-26 19:29:37 +05:00
constructor(client) {
2021-12-10 21:39:54 +05:00
super(client, {
name: "slowmode",
dirname: __dirname,
enabled: true,
guildOnly: true,
2021-12-26 19:29:37 +05:00
aliases: ["slowmotion"],
memberPermissions: ["MANAGE_GUILD"],
botPermissions: ["SEND_MESSAGES", "EMBED_LINKS"],
2021-12-10 21:39:54 +05:00
nsfw: false,
ownerOnly: false,
cooldown: 3000
});
}
2021-12-26 19:29:37 +05:00
async run(message, args, data) {
2021-12-10 21:39:54 +05:00
const channel = message.mentions.channels.filter((ch) => ch.type === "text" && ch.guild.id === message.guild.id).first();
if (!channel) return message.error("misc:INVALID_CHANNEL");
const time = args[1];
if (!time) {
if (!data.guild.slowmode.channels.find((ch) => ch.id === channel.id)) return message.error("misc:INVALID_TIME");
data.guild.slowmode.channels = data.guild.slowmode.channels.filter((ch) => ch.id !== channel.id);
data.guild.markModified("slowmode.channels");
data.guild.save();
2021-12-26 19:29:37 +05:00
message.success("administration/slowmode:DISABLED", {
prefix: data.guild.prefix,
channel: `#${channel.name}`
});
2021-12-10 21:39:54 +05:00
} else {
if (isNaN(ms(time))) return message.error("misc:INVALID_TIME");
if (data.guild.slowmode.channels.find((ch) => ch.id === channel.id)) data.guild.slowmode.channels = data.guild.slowmode.channels.filter((ch) => ch.id !== channel.id);
data.guild.slowmode.channels.push({
id: channel.id,
time: ms(time)
});
data.guild.markModified("slowmode.channels");
data.guild.save();
2021-12-26 19:29:37 +05:00
message.success("administration/slowmode:ENABLED", {
prefix: data.guild.prefix,
channel: `#${channel.name}`,
time: this.client.functions.convertTime(message.guild, ms(time))
});
2021-12-10 21:39:54 +05:00
};
}
};
module.exports = Slowmode;