update how commands are displayed in /help command

This commit is contained in:
Ayden Jahola 2024-09-26 00:14:40 +01:00
parent b4a056962b
commit 9fa6c88593
No known key found for this signature in database
GPG key ID: 71DD90AE4AE92742
4 changed files with 79 additions and 68 deletions

77
commands/core/help.js Normal file
View 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,
});
}
},
};

View file

@ -26,7 +26,7 @@ module.exports = {
)
.setTimestamp()
.setFooter({
text: `${serverName}`,
text: `${serverName} || Made with ❤️ by Ayden`,
iconURL: client.user.displayAvatarURL(),
});

View file

@ -28,7 +28,7 @@ module.exports = {
)
.setTimestamp()
.setFooter({
text: `${serverName}`,
text: `${serverName} || Made with ❤️ by Ayden`,
iconURL: client.user.displayAvatarURL(),
});

View file

@ -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,
});
}
},
};