From c855596f505b743202870f5d823f5808836af87b Mon Sep 17 00:00:00 2001 From: Taken Date: Tue, 4 Apr 2023 19:59:50 +0200 Subject: [PATCH] Adding slowmode command --- commands/slowmode.js | 59 ++++++++++++++++++++++++++++++++++++++++++++ index.js | 16 ++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 commands/slowmode.js diff --git a/commands/slowmode.js b/commands/slowmode.js new file mode 100644 index 0000000..0a8e5cd --- /dev/null +++ b/commands/slowmode.js @@ -0,0 +1,59 @@ +const { SlashCommandBuilder, PermissionFlagsBits } = require('discord.js'); +const { color } = require('../config/options.json'); + +module.exports = { + name: 'slowmode', + description: 'Set the slowmode of a channel.', + type: 'slash', + + data: new SlashCommandBuilder() + .setName('slowmode') + .setDescription('Set the slowmode of a channel.') + .addIntegerOption(option => + option + .setName('seconds') + .setDescription('The amount of seconds to set the slowmode to.')) + .addChannelOption(option => + option + .setName('channel') + .setDescription('The channel to set the slowmode of.')) + .setDefaultMemberPermissions(PermissionFlagsBits.Administrator) + .setDMPermission(false), + + async execute(interaction) { + + await interaction.deferReply({ ephermeral: true }); + + const seconds = interaction.options.getInteger('seconds') ?? 5 + const channel = interaction.options.getChannel('channel') ?? interaction.channel + const embedColor = Number(color.replace("#", "0x")); + + if (seconds > 21600) { + await channel.setRateLimitPerUser(21600) + await interaction.editReply({ + embeds: [{ + description: `Set the slowmode of ${channel} to 21600 seconds.`, + color: embedColor, + footer: { + text: interaction.guild.name + " | Developed by: @Taken#0001", + icon_url: interaction.guild.iconURL({ dynamic: true }) + } + }] + }) + return + } + + await interaction.editReply({ + embeds: [{ + description: `Set the slowmode of ${channel} to ${seconds} seconds.`, + color: embedColor, + footer: { + text: interaction.guild.name + " | Developed by: @Taken#0001", + icon_url: interaction.guild.iconURL({ dynamic: true }) + } + }] + }) + await channel.setRateLimitPerUser(seconds) + + } +} \ No newline at end of file diff --git a/index.js b/index.js index 6332385..737cb94 100644 --- a/index.js +++ b/index.js @@ -40,6 +40,22 @@ for (const file of cmdFiles) { } } +//! commands testing +const cmdTestPath = path.join(__dirname, 'commands-testing'); +const cmdTestFiles = fs.readdirSync(cmdTestPath).filter(file => file.endsWith('.js')); + +for (const file of cmdTestFiles) { + + const filePath = path.join(cmdTestPath, file); + const cmd = require(filePath); + + if ('data' in cmd && 'execute' in cmd && cmd.type === 'slash') { + client.commands.set(cmd.data.name, cmd); + } else { + console.log(`[WARNING] The command at ${filePath} is missing a required "data", "execute" or "type" property.`); + } +} + //! command handler client.on(Events.InteractionCreate, async interaction => { if(!interaction.isChatInputCommand()) return;