JaBa/commands/Moderation/announcement.js

82 lines
2.4 KiB
JavaScript
Raw Normal View History

2021-12-10 21:39:54 +05:00
const Command = require("../../base/Command.js"),
Discord = require("discord.js");
class Announcement extends Command {
constructor (client) {
super(client, {
name: "announcement",
dirname: __dirname,
enabled: true,
guildOnly: true,
aliases: [],
memberPermissions: [ "MENTION_EVERYONE" ],
botPermissions: [ "SEND_MESSAGES", "EMBED_LINKS" ],
nsfw: false,
ownerOnly: false,
cooldown: 2000
2021-12-10 21:39:54 +05:00
});
}
async run (message, args, data) {
const text = args.join(" ");
2021-12-11 01:11:50 +05:00
if (!text) return message.error("moderation/announcement:MISSING_TEXT");
if (text.length > 1030) return message.error("moderation/announcement:TOO_LONG");
2021-12-10 21:39:54 +05:00
message.delete().catch(() => {});
let mention = "";
const msg = await message.sendT("moderation/announcement:MENTION_PROMPT");
const collector = new Discord.MessageCollector(message.channel, (m) => m.author.id === message.author.id, { time: 240000 });
collector.on("collect", async (tmsg) => {
2021-12-11 01:11:50 +05:00
if (tmsg.content.toLowerCase() === message.translate("common:NO").toLowerCase()) {
2021-12-10 21:39:54 +05:00
tmsg.delete();
msg.delete();
collector.stop(true);
2021-12-11 01:11:50 +05:00
};
if (tmsg.content.toLowerCase() === message.translate("common:YES").toLowerCase()) {
2021-12-10 21:39:54 +05:00
tmsg.delete();
msg.delete();
const tmsg1 = await message.sendT("moderation/announcement:MENTION_TYPE_PROMPT");
const c = new Discord.MessageCollector(message.channel, (m) => m.author.id === message.author.id, { time: 60000 });
c.on("collect", (m) => {
2021-12-11 01:11:50 +05:00
if (m.content.toLowerCase() === "here") {
2021-12-10 21:39:54 +05:00
mention = "@here";
tmsg1.delete();
m.delete();
collector.stop(true);
c.stop(true);
2021-12-11 01:11:50 +05:00
} else if (m.content.toLowerCase() === "every") {
2021-12-10 21:39:54 +05:00
mention = "@everyone";
tmsg1.delete();
m.delete();
collector.stop(true);
c.stop(true);
2021-12-11 01:11:50 +05:00
};
2021-12-10 21:39:54 +05:00
});
c.on("end", (collected, reason) => {
2021-12-11 01:11:50 +05:00
if (reason === "time") {
2021-12-10 21:39:54 +05:00
return message.error("misc:TIMES_UP");
2021-12-11 01:11:50 +05:00
};
2021-12-10 21:39:54 +05:00
});
2021-12-11 01:11:50 +05:00
};
2021-12-10 21:39:54 +05:00
});
2021-12-11 01:11:50 +05:00
2021-12-10 21:39:54 +05:00
collector.on("end", (collected, reason) => {
2021-12-11 01:11:50 +05:00
if (reason === "time") {
2021-12-10 21:39:54 +05:00
return message.error("misc:TIMES_UP");
2021-12-11 01:11:50 +05:00
};
2021-12-10 21:39:54 +05:00
const embed = new Discord.MessageEmbed()
.setAuthor(message.translate("moderation/announcement:TITLE"))
.setColor(data.config.embed.color)
.setFooter(message.author.tag)
.setTimestamp()
.setDescription(text);
2021-12-11 01:11:50 +05:00
2021-12-10 21:39:54 +05:00
message.channel.send(mention, embed);
});
}
2021-12-11 01:11:50 +05:00
};
2021-12-10 21:39:54 +05:00
module.exports = Announcement;