'v3.3.2 The Help Fix' (#17) from v3.3.2 into main

Reviewed-on: #17

Vastly improved the help message formatting and fixed a bug causing the help message to crash due to too many fields. Fixed by moving away from fields, then by filtering the command names to be unique. Aliases are being loaded as entirely new commands which will need to be fixed later.
This commit is contained in:
Skylar Grant 2024-09-24 02:05:13 +00:00
commit e5d520a73b
5 changed files with 47 additions and 57 deletions

1
.gitignore vendored
View File

@ -3,6 +3,7 @@
package-lock.json package-lock.json
.VSCodeCounter/ .VSCodeCounter/
.env* .env*
*.env
# Custom folders # Custom folders
# gifs/* # gifs/*

View File

@ -210,51 +210,61 @@ const functions = {
const helpEmbed = new Discord.MessageEmbed() const helpEmbed = new Discord.MessageEmbed()
.setColor('BLUE') .setColor('BLUE')
.setAuthor({name: 'Help Page'}) .setAuthor({name: 'Help Page'})
.setDescription(strings.help.description)
.setThumbnail(strings.urls.avatar); .setThumbnail(strings.urls.avatar);
// Construct the Slash Commands help // Construct the Slash Commands help
let slashCommandsFields = []; let slashCommandsFields = [];
let slashSeenNames = new Array();
const slashCommandsMap = interaction.client.slashCommands.map(e => { const slashCommandsMap = interaction.client.slashCommands.map(e => {
return { if (!slashSeenNames.includes(e.data.name)) {
name: e.data.name, slashSeenNames.push(e.data.name);
description: e.data.description return {
}; name: e.data.name,
}) description: e.data.description
};
} else {
return null;
}
});
for (const e of slashCommandsMap) { for (const e of slashCommandsMap) {
slashCommandsFields.push({ slashCommandsFields.push(`- \`/${e.name}\` - ${e.description}`);
name: `- /${e.name}`,
value: e.description,
inline: false,
});
} }
console.log(slashCommandsFields);
// Construct the Dot Commands Help // Construct the Dot Commands Help
let dotCommandsFields = []; let dotCommandsFields = new Array();
let dotSeenNames = new Array();
const dotCommandsMap = interaction.client.dotCommands.map(e => { const dotCommandsMap = interaction.client.dotCommands.map(e => {
return { if (!dotSeenNames.includes(e.name)) {
name: e.name, dotSeenNames.push(e.name);
description: e.description, return {
usage: e.usage name: e.name,
}; description: e.description,
usage: e.usage
};
} else {
return null;
}
}); });
for (const e of dotCommandsMap) { for (const e of dotCommandsMap) {
dotCommandsFields.push({ if (e != null) {
name: `- .${e.name}`, dotCommandsFields.push(`- \`.${e.name}\` - ${e.description} - ${e.usage}`);
value: `${e.description}\nUsage: ${e.usage}`, }
inline: false,
});
} }
console.log(dotCommandsFields);
helpEmbed.addField('Slash Commands', strings.help.slash); // Construct the Description Fields
helpEmbed.addFields(slashCommandsFields); const descriptionFields = [
helpEmbed.addField('Dot Commands', strings.help.dot); `${strings.help.description}\n`,
helpEmbed.addFields(dotCommandsFields); `**Slash Commands**\n${strings.help.slash}\n`,
`${slashCommandsFields.join('\n')}\n`,
`**Dot Commands**\n${strings.help.dot}\n`,
`${dotCommandsFields.join('\n')}`
];
// Set the description
helpEmbed.setDescription(descriptionFields.join('\n'));
return { embeds: [ return { embeds: [
helpEmbed helpEmbed

View File

@ -1,6 +1,6 @@
{ {
"name": "nodbot", "name": "nodbot",
"version": "3.3.1", "version": "3.3.2",
"description": "Nods and Nod Accessories, now with ChatGPT!", "description": "Nods and Nod Accessories, now with ChatGPT!",
"main": "main.js", "main": "main.js",
"dependencies": { "dependencies": {

View File

@ -4,29 +4,8 @@ const fn = require('../functions.js');
module.exports = { module.exports = {
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
.setName('help') .setName('help')
.setDescription('Send the help page.') .setDescription('Send the help page.'),
// .addStringOption(option =>
// option.setName('location')
// .setDescription('Send help in this channel or in DMs?')
// .setRequired(true)
// .addChoice('Here', 'channel')
// .addChoice('DMs', 'dm'))
,
async execute(interaction) { async execute(interaction) {
// switch (interaction.options.getString('location')) {
// case 'channel':
// await interaction.reply(fn.embeds.help(interaction));
// break;
// case 'dm':
// await interaction.user.createDM().then(channel => {
// channel.send(fn.embeds.help(interaction));
// interaction.reply({content: 'I\'ve sent you a copy of my help page.', ephemeral: true});
// });
// break;
// default:
// interaction.reply('There was an error, please try again.');
// break;
// }
await interaction.reply(fn.embeds.help(interaction)); await interaction.reply(fn.embeds.help(interaction));
}, }
}; };

View File

@ -1,8 +1,8 @@
{ {
"help": { "help": {
"description": "Hi there! Thanks for checking out NodBot. NodBot is used in two distinct ways: with 'Slash Commands' (/help), and with 'Dot Commands' (nod.gif). The two types will be outlined below, along with usage examples.", "description": "Hi there! Thanks for checking out NodBot. NodBot is used in two distinct ways: with 'Slash Commands' (`/help`), and with 'Dot Commands' (`nod.gif`). The two types will be outlined below, along with usage examples.",
"slash": "Slash Commands always begin with a / and a menu will pop up to help complete the commands.", "slash": "Slash Commands always begin with a `/` and a menu will pop up to help complete the commands.",
"dot": "Dot Commands have the command at the end of the message, for example to search for a gif of 'nod', type 'nod.gif'" "dot": "Dot Commands have the command at the end of the message, for example to search for a gif of `nod`, type `nod.gif`"
}, },
"emoji": { "emoji": {
"joint": "<:joint:862082955902976000>", "joint": "<:joint:862082955902976000>",