|
| 1 | +const { SlashCommandBuilder } = require("@discordjs/builders"); |
| 2 | +const { EmbedBuilder, PermissionsBitField } = require("discord.js"); |
| 3 | + |
| 4 | +module.exports = { |
| 5 | + helpinfo: |
| 6 | + "This comand is used to warn people aswell as to see a list of warnings", |
| 7 | + data: new SlashCommandBuilder() |
| 8 | + .setName("warn") |
| 9 | + .setDescription("Warn a user or see a list of warnings") |
| 10 | + .addSubcommand((subcommand) => |
| 11 | + subcommand |
| 12 | + .setName("warn") |
| 13 | + .setDescription("warn a user") |
| 14 | + .addUserOption((option) => |
| 15 | + option |
| 16 | + .setName("user") |
| 17 | + .setDescription("user to mute") |
| 18 | + .setRequired(true) |
| 19 | + ) |
| 20 | + .addStringOption((option) => |
| 21 | + option |
| 22 | + .setName("reason") |
| 23 | + .setDescription("reason for warning") |
| 24 | + .setMaxLength(150) |
| 25 | + .setRequired(true) |
| 26 | + ) |
| 27 | + ) |
| 28 | + .addSubcommand((subcommand) => |
| 29 | + subcommand |
| 30 | + .setName("list") |
| 31 | + .setDescription("see a list of warnings") |
| 32 | + .addUserOption((option) => |
| 33 | + option |
| 34 | + .setName("user") |
| 35 | + .setDescription("user to see warnings for") |
| 36 | + .setRequired(true) |
| 37 | + ) |
| 38 | + ) |
| 39 | + .addSubcommand((subcommand) => |
| 40 | + subcommand |
| 41 | + .setName("remove") |
| 42 | + .setDescription("remove a warning") |
| 43 | + .addUserOption((option) => |
| 44 | + option |
| 45 | + .setName("user") |
| 46 | + .setDescription("user to remove warning from") |
| 47 | + .setRequired(true) |
| 48 | + ) |
| 49 | + .addStringOption((option) => |
| 50 | + option |
| 51 | + .setName("ID") |
| 52 | + .setDescription("ID of the warning to remove") |
| 53 | + .setRequired(true) |
| 54 | + ) |
| 55 | + ), |
| 56 | + |
| 57 | + async execute(interaction) { |
| 58 | + const subcommand = interaction.options.getSubcommand(); |
| 59 | + const member = interaction.guild.members.cache.get( |
| 60 | + interaction.options.getUser("user").id |
| 61 | + ); |
| 62 | + const guild = interaction.guild; |
| 63 | + const moderator = interaction.guild.members.cache.get(interaction.user.id); |
| 64 | + |
| 65 | + // Checks before mute or unmute |
| 66 | + if (!member) { |
| 67 | + return interaction.reply({ |
| 68 | + content: "User is not in the guild", |
| 69 | + ephemeral: true, |
| 70 | + }); |
| 71 | + } |
| 72 | + |
| 73 | + // makes sure the user has the kick permission |
| 74 | + if (!moderator.permissions.has(PermissionsBitField.Flags.ModerateMembers)) { |
| 75 | + return interaction.reply({ |
| 76 | + content: "You do not have permission to mute/unmute members!", |
| 77 | + ephemeral: true, |
| 78 | + }); |
| 79 | + } |
| 80 | + |
| 81 | + // makes sure the user is not the bot |
| 82 | + if (member.bot) { |
| 83 | + return interaction.reply({ |
| 84 | + content: "You cannot warn a bot!", |
| 85 | + ephemeral: true, |
| 86 | + }); |
| 87 | + } |
| 88 | + |
| 89 | + // makes sure the user is not admin |
| 90 | + if (member === moderator) { |
| 91 | + return interaction.reply({ |
| 92 | + content: "You cannot do this to yourself!", |
| 93 | + ephemeral: true, |
| 94 | + }); |
| 95 | + } |
| 96 | + |
| 97 | + // IMPORTANT THIS IS WHERE THE WARN COMMAND IS HANDLED |
| 98 | + |
| 99 | + if (subcommand === "warn") { |
| 100 | + const reason = interaction.options.getString("reason"); |
| 101 | + |
| 102 | + /* |
| 103 | + This is where you need to write the code to interact with the database for when a user is warned |
| 104 | +
|
| 105 | + you can get the targeted user from the `member` variable |
| 106 | + you can get the moderator from the `moderator` variable |
| 107 | + you cant get the reason from the `reason` variable |
| 108 | + you can get the guild from the `guild` variable |
| 109 | + */ |
| 110 | + |
| 111 | + //reply to the slash command with a succesfful message |
| 112 | + interaction.reply({ |
| 113 | + content: `${moderator} has warned ${member.user.tag} for ${reason}`, |
| 114 | + }); |
| 115 | + } else if (subcommand === "list") { |
| 116 | + /* |
| 117 | + This is where you need to write the code to interact with the database for when a admin is requesting a list of warnings for a user |
| 118 | +
|
| 119 | + you can get the targeted user from the `member` variable |
| 120 | + you can get the moderator from the `moderator` variable |
| 121 | + you cant get the reason from the `reason` variable |
| 122 | + you can get the guild from the `guild` variable |
| 123 | + */ |
| 124 | + |
| 125 | + const mockWarnings = [ |
| 126 | + { |
| 127 | + id: "some random id dosnt matter how it is generated", |
| 128 | + moderator: "Moderator#1234", |
| 129 | + reason: "This is a mock warning", |
| 130 | + date: "2020-01-01", |
| 131 | + }, |
| 132 | + { |
| 133 | + id: "some random id dosnt matter how it is generated", |
| 134 | + moderator: "Moderator#1234", |
| 135 | + reason: "This is a mock warning", |
| 136 | + date: "2020-01-02", |
| 137 | + }, |
| 138 | + ]; |
| 139 | + |
| 140 | + // use this embed to display the list of warnings |
| 141 | + const ResponseEmbed = new EmbedBuilder() |
| 142 | + .setTitle("Warnings for " + member.user.tag) |
| 143 | + .addFields( |
| 144 | + mockWarnings.map((warning) => { |
| 145 | + return { |
| 146 | + name: `${warning.moderator} - ${warning.id}`, |
| 147 | + value: `${warning.reason}`, |
| 148 | + }; |
| 149 | + }) |
| 150 | + ) |
| 151 | + .setColor("#ff0000") |
| 152 | + .setTimestamp(); |
| 153 | + |
| 154 | + //reply to the slash command with a succesfful message |
| 155 | + interaction.reply({ |
| 156 | + embeds: [ResponseEmbed], |
| 157 | + }); |
| 158 | + } else if (subcommand === "remove") { |
| 159 | + const ID = interaction.options.getString("ID"); |
| 160 | + |
| 161 | + /* |
| 162 | + This is where you need to write the code to interact with the database for when a admin is removing a warning from a user |
| 163 | +
|
| 164 | + you can get the id of the warning from the `ID` variable |
| 165 | + you can get the targeted user from the `member` variable |
| 166 | + you can get the moderator from the `moderator` variable |
| 167 | + you can get the guild from the `guild` variable |
| 168 | +
|
| 169 | + */ |
| 170 | + |
| 171 | + interaction.reply({ |
| 172 | + content: `${moderator} has removed a warning from ${member.user.tag}`, |
| 173 | + }); |
| 174 | + } |
| 175 | + }, |
| 176 | +}; |
0 commit comments