mirror of
				https://github.com/aydenjahola/discord-multipurpose-bot.git
				synced 2025-11-04 00:01:41 +00:00 
			
		
		
		
	update how commands are displayed in /help command
This commit is contained in:
		
							parent
							
								
									b4a056962b
								
							
						
					
					
						commit
						9fa6c88593
					
				
					 4 changed files with 79 additions and 68 deletions
				
			
		
							
								
								
									
										77
									
								
								commands/core/help.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										77
									
								
								commands/core/help.js
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -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,
 | 
				
			||||||
 | 
					      });
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
| 
						 | 
					@ -26,7 +26,7 @@ module.exports = {
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        .setTimestamp()
 | 
					        .setTimestamp()
 | 
				
			||||||
        .setFooter({
 | 
					        .setFooter({
 | 
				
			||||||
          text: `${serverName}`,
 | 
					          text: `${serverName} || Made with ❤️ by Ayden`,
 | 
				
			||||||
          iconURL: client.user.displayAvatarURL(),
 | 
					          iconURL: client.user.displayAvatarURL(),
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -28,7 +28,7 @@ module.exports = {
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        .setTimestamp()
 | 
					        .setTimestamp()
 | 
				
			||||||
        .setFooter({
 | 
					        .setFooter({
 | 
				
			||||||
          text: `${serverName}`,
 | 
					          text: `${serverName} || Made with ❤️ by Ayden`,
 | 
				
			||||||
          iconURL: client.user.displayAvatarURL(),
 | 
					          iconURL: client.user.displayAvatarURL(),
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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,
 | 
					 | 
				
			||||||
      });
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  },
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
		Loading…
	
		Reference in a new issue