diff --git a/commands/core/help.js b/commands/core/help.js new file mode 100644 index 0000000..365facc --- /dev/null +++ b/commands/core/help.js @@ -0,0 +1,77 @@ +const { + SlashCommandBuilder, + EmbedBuilder, + PermissionsBitField, +} = require("discord.js"); + +module.exports = { + data: new SlashCommandBuilder() + .setName("help") + .setDescription("Lists all available commands"), + + async execute(interaction, client) { + try { + // Check if the user has the Manage Roles permission + const isMod = interaction.member.permissions.has( + PermissionsBitField.Flags.ManageRoles + ); + + const serverName = interaction.guild.name; + + const helpEmbed = new EmbedBuilder() + .setColor("#0099ff") + .setTitle("Available Commands") + .setDescription( + "This bot comes from an Open Source project developed by [Ayden](https://github.com/aydenjahola/discord-multipurpose-bot)\n\nHere are all the available commands:" + ) + .setTimestamp() + .setFooter({ + text: `${serverName} || Made with ❤️ by Ayden`, + iconURL: client.user.displayAvatarURL(), + }); + + // Group commands into general and mod-only + const generalCommands = []; + const modCommands = []; + + client.commands.forEach((command) => { + const commandLine = `/${command.data.name} - ${command.data.description}`; + if (!command.isModOnly) { + generalCommands.push(commandLine); + } else if (isMod) { + modCommands.push(`${commandLine} (Mods only)`); + } + }); + + helpEmbed.addFields({ + name: `General Commands (${generalCommands.length} available)`, + value: + generalCommands.length > 0 + ? generalCommands.join("\n") + : "No general commands available.", + inline: false, + }); + + if (isMod) { + helpEmbed.addFields({ + name: `Mod-Only Commands (${modCommands.length} available)`, + value: + modCommands.length > 0 + ? modCommands.join("\n") + : "No mod-only commands available.", + inline: false, + }); + } + + await interaction.reply({ + embeds: [helpEmbed], + }); + } catch (error) { + console.error("Error executing the help command:", error); + await interaction.reply({ + content: "There was an error while executing this command!", + ephemeral: true, + }); + } + }, +}; diff --git a/commands/utility/ping.js b/commands/core/ping.js similarity index 92% rename from commands/utility/ping.js rename to commands/core/ping.js index 4b962da..c338d8a 100644 --- a/commands/utility/ping.js +++ b/commands/core/ping.js @@ -26,7 +26,7 @@ module.exports = { ) .setTimestamp() .setFooter({ - text: `${serverName}`, + text: `${serverName} || Made with ❤️ by Ayden`, iconURL: client.user.displayAvatarURL(), }); diff --git a/commands/utility/uptime.js b/commands/core/uptime.js similarity index 93% rename from commands/utility/uptime.js rename to commands/core/uptime.js index 88544f9..2bba73f 100644 --- a/commands/utility/uptime.js +++ b/commands/core/uptime.js @@ -28,7 +28,7 @@ module.exports = { ) .setTimestamp() .setFooter({ - text: `${serverName}`, + text: `${serverName} || Made with ❤️ by Ayden`, iconURL: client.user.displayAvatarURL(), }); diff --git a/commands/utility/help.js b/commands/utility/help.js deleted file mode 100644 index b84c980..0000000 --- a/commands/utility/help.js +++ /dev/null @@ -1,66 +0,0 @@ -const { - SlashCommandBuilder, - EmbedBuilder, - PermissionsBitField, -} = require("discord.js"); - -module.exports = { - data: new SlashCommandBuilder() - .setName("help") - .setDescription("Lists all available commands"), - - async execute(interaction, client) { - try { - // Check if the user has the Manage Roles permission - const isMod = interaction.member.permissions.has( - PermissionsBitField.Flags.ManageRoles - ); - - const serverName = interaction.guild.name; - - const helpEmbed = new EmbedBuilder() - .setColor("#0099ff") - .setTitle("Available Commands") - .setDescription("Here are all the available commands:") - .setTimestamp() - .setFooter({ - text: `${serverName}`, - iconURL: client.user.displayAvatarURL(), - }); - - // Add general commands - client.commands.forEach((command) => { - if (!command.isModOnly) { - helpEmbed.addFields({ - name: `/${command.data.name}`, - value: command.data.description, - inline: false, - }); - } - }); - - // Add mod-only commands if the user is a mod - if (isMod) { - client.commands.forEach((command) => { - if (command.isModOnly) { - helpEmbed.addFields({ - name: `/${command.data.name}`, - value: command.data.description + " (Mods only)", - inline: false, - }); - } - }); - } - - await interaction.reply({ - embeds: [helpEmbed], - }); - } catch (error) { - console.error("Error executing the help command:", error); - await interaction.reply({ - content: "There was an error while executing this command!", - ephemeral: true, - }); - } - }, -};