Advertisement
Guest User

Untitled

a guest
Sep 14th, 2024
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.19 KB | None | 0 0
  1. const { PermissionFlagsBits, EmbedBuilder } = require("discord.js");
  2. const moderationSchema = require("../schemas/moderation");
  3. const mConfig = require("../messageConfig.json");
  4.  
  5. module.exports = {
  6. customId: "banBtn",
  7. userPermissions: [],
  8. botPermissions: [PermissionFlagsBits.BanMembers],
  9.  
  10. run: async (client, interaction) => {
  11. const { message, channel, guildId, guild, user } = interaction;
  12.  
  13.  
  14. const userId = interaction.customId.split("_")[1];
  15.  
  16.  
  17. if (!userId) {
  18. const errorEmbed = new EmbedBuilder()
  19. .setColor(mConfig.embedColorError)
  20. .setDescription("\`❌\` Unable to retrieve user ID from the interaction.");
  21. return interaction.reply({ embeds: [errorEmbed], ephemeral: true });
  22. }
  23.  
  24. // Fetch the target member using the userId
  25. const targetMember = await guild.members.fetch(userId).catch(() => {
  26. const errorEmbed = new EmbedBuilder()
  27. .setColor(mConfig.embedColorError)
  28. .setDescription("\`❌\` User not found in this guild.");
  29. return interaction.reply({ embeds: [errorEmbed], ephemeral: true });
  30. });
  31.  
  32. const rEmbed = new EmbedBuilder()
  33. .setColor("FFFFFF")
  34. .setFooter({ text: `${client.user.username} - Moderate user` })
  35. .setAuthor({ name: `User ID: ${userId}` })
  36. .setDescription(`
  37. \`❔\` 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\`.`);
  38.  
  39. message.edit({ embeds: [rEmbed], components: [] });
  40.  
  41. const filter = (m) => m.author.id === user.id;
  42. const reasonCollector = await channel.awaitMessages({ filter, max: 1, time: 15_000, errors: ["time"] })
  43. .then((reason) => {
  44. if (reason.first().content.toLowerCase() === "cancel") {
  45. reason.first().delete();
  46. rEmbed
  47. .setColor(`${mConfig.embedColorError}`)
  48. .setDescription("\`❌\` Moderation cancelled.");
  49. message.edit({ embeds: [rEmbed] });
  50. setTimeout(() => {
  51. message.delete();
  52. }, 2_000);
  53. return;
  54. }
  55. return reason;
  56. })
  57. .catch(() => {
  58. rEmbed
  59. .setColor(`${mConfig.embedColorError}`)
  60. .setDescription("\`❌\` Moderation cancelled.");
  61. message.edit({ embeds: [rEmbed] });
  62. setTimeout(() => {
  63. message.delete();
  64. }, 2_000);
  65. return;
  66. });
  67.  
  68. const reasonObj = reasonCollector?.first();
  69. if (!reasonObj) return;
  70.  
  71. let reason = reasonObj.content;
  72. if (reasonObj.content === "-") {
  73. reason = "No reason specified.";
  74. }
  75. reasonObj.delete();
  76.  
  77.  
  78. let dataMG = await moderationSchema.find({ MultiGuilded: true });
  79. if (dataMG) {
  80. let i;
  81. for (i = 0; i < dataMG.length; i++) {
  82. const { GuildID, LogChannelID } = dataMG[i];
  83. if (GuildID === guildId) continue;
  84.  
  85. const externalGuild = client.guilds.cache.get(GuildID);
  86. const externalLogChannel = externalGuild.channels.cache.get(LogChannelID);
  87. const externalBot = await externalGuild.members.fetch(client.user.id);
  88.  
  89. try {
  90.  
  91. await externalGuild.bans.create(userId, { deleteMessageSeconds: 60 * 60 * 24 * 7, reason: "Automatic multi-guilded ban." }); // "deleteMessageSeconds" is optional.
  92.  
  93. const lEmbed = new EmbedBuilder()
  94. .setColor("FFFFFF")
  95. .setTitle("\`⛔\` User banned")
  96. .setDescription(`\`💡\` To unban the user, use \`/unban ${userId}\` to revoke this ban.`)
  97. .addFields(
  98. { name: "Banned by", value: `<@${client.user.id}>`, inline: true },
  99. { name: "Reason", value: "Automatic multi-guilded ban.", inline: true }
  100. )
  101. .setFooter({ iconURL: `${client.user.displayAvatarURL({ dynamic: true })}`, text: `${client.user.username} - Logging system` });
  102.  
  103. externalLogChannel.send({ embeds: [lEmbed] });
  104. } catch (err) {
  105. continue;
  106. }
  107. }
  108. }
  109.  
  110.  
  111.  
  112. await guild.bans.create(userId, { deleteMessageSeconds: 60 * 60 * 24 * 7, reason: `${reason}` });
  113.  
  114. let dataGD = await moderationSchema.findOne({ GuildID: guildId });
  115. const { LogChannelID } = dataGD;
  116. const loggingChannel = guild.channels.cache.get(LogChannelID);
  117.  
  118. const lEmbed = new EmbedBuilder()
  119. .setColor("FF0000")
  120. .setTitle("\`⛔\` User banned")
  121. .setDescription(`\`💡\` To unban the user, use \`/unban ${userId}\` to revoke this ban.`)
  122. .addFields(
  123. { name: "Banned by", value: `<@${user.id}>`, inline: true },
  124. { name: "Reason", value: `${reason}`, inline: true }
  125. )
  126. .setFooter({ iconURL: `${client.user.displayAvatarURL({ dynamic: true })}`, text: `${client.user.username} - Logging system` });
  127.  
  128. loggingChannel.send({ embeds: [lEmbed] });
  129.  
  130. rEmbed
  131. .setColor(`${mConfig.embedColorSuccess}`)
  132. .setDescription(`\`✅\` Successfully banned the user.`);
  133.  
  134. message.edit({ embeds: [rEmbed] });
  135. setTimeout(() => {
  136. message.delete();
  137. }, 2_000);
  138. }
  139. };
  140.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement