JaBa/commands/Moderation/announcement.js

96 lines
2.5 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 {
2021-12-26 19:29:37 +05:00
constructor(client) {
2021-12-10 21:39:54 +05:00
super(client, {
name: "announcement",
dirname: __dirname,
enabled: true,
guildOnly: true,
aliases: ["ann"],
2021-12-26 19:29:37 +05:00
memberPermissions: ["MENTION_EVERYONE"],
botPermissions: ["SEND_MESSAGES", "EMBED_LINKS"],
2021-12-10 21:39:54 +05:00
nsfw: false,
ownerOnly: false,
cooldown: 1000
2021-12-10 21:39:54 +05:00
});
}
2021-12-26 19:29:37 +05:00
async run(message, args, data) {
2021-12-10 21:39:54 +05:00
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");
2022-01-03 23:20:33 +05:00
const filter = m => m.author.id === message.author.id;
const collector = new Discord.MessageCollector(message.channel, {
filter,
2021-12-26 19:29:37 +05:00
time: 240000
});
2021-12-10 21:39:54 +05:00
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");
2022-01-03 23:20:33 +05:00
const filter = m => m.author.id === message.author.id;
const c = new Discord.MessageCollector(message.channel, {
filter,
2021-12-26 19:29:37 +05:00
time: 60000
});
2021-12-10 21:39:54 +05:00
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-30 20:03:36 +05:00
} else if (m.content.toLowerCase() === "everyone") {
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-26 19:29:37 +05:00
if (reason === "time") return message.error("misc:TIMES_UP");
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-26 19:29:37 +05:00
if (reason === "time") return message.error("misc:TIMES_UP");
2021-12-10 21:39:54 +05:00
const embed = new Discord.MessageEmbed()
2022-01-04 00:35:11 +05:00
.setAuthor({
name: message.translate("moderation/announcement:TITLE")
})
2021-12-10 21:39:54 +05:00
.setColor(data.config.embed.color)
2022-01-04 00:35:11 +05:00
.setFooter({
text: message.author.tag
})
2021-12-10 21:39:54 +05:00
.setTimestamp()
.setDescription(text);
2021-12-11 01:11:50 +05:00
2022-01-04 00:35:11 +05:00
message.channel.send({
content: mention,
embeds: [embed]
});
2021-12-10 21:39:54 +05:00
});
}
2021-12-11 01:11:50 +05:00
};
2021-12-10 21:39:54 +05:00
module.exports = Announcement;