Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const { PermissionFlagsBits, EmbedBuilder } = require("discord.js");
- const moderationSchema = require("../schemas/moderation");
- const mConfig = require("../messageConfig.json");
- module.exports = {
- customId: "banBtn",
- userPermissions: [],
- botPermissions: [PermissionFlagsBits.BanMembers],
- run: async (client, interaction) => {
- const { message, channel, guildId, guild, user } = interaction;
- const userId = interaction.customId.split("_")[1];
- if (!userId) {
- const errorEmbed = new EmbedBuilder()
- .setColor(mConfig.embedColorError)
- .setDescription("\`❌\` Unable to retrieve user ID from the interaction.");
- return interaction.reply({ embeds: [errorEmbed], ephemeral: true });
- }
- // Fetch the target member using the userId
- const targetMember = await guild.members.fetch(userId).catch(() => {
- const errorEmbed = new EmbedBuilder()
- .setColor(mConfig.embedColorError)
- .setDescription("\`❌\` User not found in this guild.");
- return interaction.reply({ embeds: [errorEmbed], ephemeral: true });
- });
- const rEmbed = new EmbedBuilder()
- .setColor("FFFFFF")
- .setFooter({ text: `${client.user.username} - Moderate user` })
- .setAuthor({ name: `User ID: ${userId}` })
- .setDescription(`
- \`❔\` What is the reason to ban the user?\n\`❕\` You have 15 seconds to reply. After this time, the moderation will be automatically cancelled.\n\n\`💡\` To continue without a reason, answer with \`-\`.\n\`💡\` To cancel the moderation, answer with \`cancel\`.`);
- message.edit({ embeds: [rEmbed], components: [] });
- const filter = (m) => m.author.id === user.id;
- const reasonCollector = await channel.awaitMessages({ filter, max: 1, time: 15_000, errors: ["time"] })
- .then((reason) => {
- if (reason.first().content.toLowerCase() === "cancel") {
- reason.first().delete();
- rEmbed
- .setColor(`${mConfig.embedColorError}`)
- .setDescription("\`❌\` Moderation cancelled.");
- message.edit({ embeds: [rEmbed] });
- setTimeout(() => {
- message.delete();
- }, 2_000);
- return;
- }
- return reason;
- })
- .catch(() => {
- rEmbed
- .setColor(`${mConfig.embedColorError}`)
- .setDescription("\`❌\` Moderation cancelled.");
- message.edit({ embeds: [rEmbed] });
- setTimeout(() => {
- message.delete();
- }, 2_000);
- return;
- });
- const reasonObj = reasonCollector?.first();
- if (!reasonObj) return;
- let reason = reasonObj.content;
- if (reasonObj.content === "-") {
- reason = "No reason specified.";
- }
- reasonObj.delete();
- let dataMG = await moderationSchema.find({ MultiGuilded: true });
- if (dataMG) {
- let i;
- for (i = 0; i < dataMG.length; i++) {
- const { GuildID, LogChannelID } = dataMG[i];
- if (GuildID === guildId) continue;
- const externalGuild = client.guilds.cache.get(GuildID);
- const externalLogChannel = externalGuild.channels.cache.get(LogChannelID);
- const externalBot = await externalGuild.members.fetch(client.user.id);
- try {
- await externalGuild.bans.create(userId, { deleteMessageSeconds: 60 * 60 * 24 * 7, reason: "Automatic multi-guilded ban." }); // "deleteMessageSeconds" is optional.
- const lEmbed = new EmbedBuilder()
- .setColor("FFFFFF")
- .setTitle("\`⛔\` User banned")
- .setDescription(`\`💡\` To unban the user, use \`/unban ${userId}\` to revoke this ban.`)
- .addFields(
- { name: "Banned by", value: `<@${client.user.id}>`, inline: true },
- { name: "Reason", value: "Automatic multi-guilded ban.", inline: true }
- )
- .setFooter({ iconURL: `${client.user.displayAvatarURL({ dynamic: true })}`, text: `${client.user.username} - Logging system` });
- externalLogChannel.send({ embeds: [lEmbed] });
- } catch (err) {
- continue;
- }
- }
- }
- await guild.bans.create(userId, { deleteMessageSeconds: 60 * 60 * 24 * 7, reason: `${reason}` });
- let dataGD = await moderationSchema.findOne({ GuildID: guildId });
- const { LogChannelID } = dataGD;
- const loggingChannel = guild.channels.cache.get(LogChannelID);
- const lEmbed = new EmbedBuilder()
- .setColor("FF0000")
- .setTitle("\`⛔\` User banned")
- .setDescription(`\`💡\` To unban the user, use \`/unban ${userId}\` to revoke this ban.`)
- .addFields(
- { name: "Banned by", value: `<@${user.id}>`, inline: true },
- { name: "Reason", value: `${reason}`, inline: true }
- )
- .setFooter({ iconURL: `${client.user.displayAvatarURL({ dynamic: true })}`, text: `${client.user.username} - Logging system` });
- loggingChannel.send({ embeds: [lEmbed] });
- rEmbed
- .setColor(`${mConfig.embedColorSuccess}`)
- .setDescription(`\`✅\` Successfully banned the user.`);
- message.edit({ embeds: [rEmbed] });
- setTimeout(() => {
- message.delete();
- }, 2_000);
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement