Skip to content

Commit 7041aa6

Browse files
authored
Merge pull request #1188 from LewdHuTao/patch1
fix: help command
2 parents 3a02c36 + ca3e26e commit 7041aa6

File tree

1 file changed

+126
-125
lines changed

1 file changed

+126
-125
lines changed

commands/slash/help.js

Lines changed: 126 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -1,134 +1,135 @@
11
const SlashCommand = require("../../lib/SlashCommand");
22
const {
3-
Client,
4-
Interaction,
5-
MessageActionRow,
6-
MessageButton,
7-
MessageEmbed,
3+
Client,
4+
Interaction,
5+
MessageActionRow,
6+
MessageButton,
7+
MessageEmbed,
88
} = require("discord.js");
99
const LoadCommands = require("../../util/loadCommands");
1010
const { filter } = require("lodash");
1111

1212
const command = new SlashCommand()
13-
.setName("help")
14-
.setDescription("Shows this list")
15-
.setRun(async (client, interaction) => {
16-
await interaction.deferReply().catch((_) => {
17-
});
18-
// map the commands name and description to the embed
19-
const commands = await LoadCommands().then((cmds) => {
20-
return [].concat(cmds.slash) /*.concat(cmds.context)*/;
21-
});
22-
// from commands remove the ones that have "null" in the description
23-
const filteredCommands = commands.filter(
24-
(cmd) => cmd.description != "null",
25-
);
26-
//console.log(filteredCommands);
27-
const totalCmds = filteredCommands.length;
28-
let maxPages = Math.ceil(totalCmds / client.config.helpCmdPerPage);
29-
30-
// if git exists, then get commit hash
31-
let gitHash = "";
32-
try {
33-
gitHash = require("child_process")
34-
.execSync("git rev-parse --short HEAD")
35-
.toString()
36-
.trim();
37-
} catch (e) {
38-
// do nothing
39-
gitHash = "unknown";
40-
}
41-
42-
// default Page No.
43-
let pageNo = 0;
44-
45-
const helpEmbed = new MessageEmbed()
46-
.setColor(client.config.embedColor)
47-
.setAuthor({
48-
name: `Commands of ${ client.user.username }`,
49-
iconURL: client.config.iconURL,
50-
})
51-
.setTimestamp()
52-
.setFooter({ text: `Page ${ pageNo + 1 } / ${ maxPages }` });
53-
54-
// initial temporary array
55-
var tempArray = filteredCommands.slice(
56-
pageNo * client.config.cmdPerPage,
57-
pageNo * client.config.cmdPerPage + client.config.cmdPerPage,
58-
);
59-
60-
tempArray.forEach((cmd) => {
61-
helpEmbed.addFields({name: cmd.name, value: cmd.description});
62-
});
63-
helpEmbed.addFields({
64-
name: "Credits",
65-
value: `Discord Music Bot Version: v${
66-
require("../../package.json").version
67-
}; Build: ${ gitHash }` +
68-
"\n" +
69-
`[✨ Support Server](${ client.config.supportServer }) | [Issues](${ client.config.Issues }) | [Source](https://github.com/SudhanPlayz/Discord-MusicBot/tree/v5) | [Invite Me](https://discord.com/oauth2/authorize?client_id=${ client.config.clientId }&permissions=${ client.config.permissions }&scope=bot%20applications.commands)`,
70-
});
71-
72-
// Construction of the buttons for the embed
73-
const getButtons = (pageNo) => {
74-
return new MessageActionRow().addComponents(
75-
new MessageButton()
76-
.setCustomId("help_cmd_but_2_app")
77-
.setEmoji("◀️")
78-
.setStyle("PRIMARY")
79-
.setDisabled(pageNo == 0),
80-
new MessageButton()
81-
.setCustomId("help_cmd_but_1_app")
82-
.setEmoji("▶️")
83-
.setStyle("PRIMARY")
84-
.setDisabled(pageNo == maxPages - 1),
85-
);
86-
};
87-
88-
const tempMsg = await interaction.editReply({
89-
embeds: [helpEmbed],
90-
components: [getButtons(pageNo)],
91-
fetchReply: true,
92-
});
93-
const collector = tempMsg.createMessageComponentCollector({
94-
time: 600000,
95-
componentType: "BUTTON",
96-
});
97-
98-
collector.on("collect", async (iter) => {
99-
if (iter.customId === "help_cmd_but_1_app") {
100-
pageNo++;
101-
} else if (iter.customId === "help_cmd_but_2_app") {
102-
pageNo--;
103-
}
104-
105-
helpEmbed.fields = [];
106-
107-
var tempArray = filteredCommands.slice(
108-
pageNo * client.config.cmdPerPage,
109-
pageNo * client.config.cmdPerPage + client.config.cmdPerPage,
110-
);
111-
112-
tempArray.forEach((cmd) => {
113-
//console.log(cmd);
114-
helpEmbed
115-
.addFields({ name: cmd.name, value: cmd.description})
116-
.setFooter({ text: `Page ${ pageNo + 1 } / ${ maxPages }` });
117-
});
118-
helpEmbed.addFields({
119-
name: "Credits",
120-
value: `Discord Music Bot Version: v${
121-
require("../../package.json").version
122-
}; Build: ${ gitHash }` +
123-
"\n" +
124-
`[✨ Support Server](${ client.config.supportServer }) | [Issues](${ client.config.Issues }) | [Source](https://github.com/SudhanPlayz/Discord-MusicBot/tree/v5) | [Invite Me](https://discord.com/oauth2/authorize?client_id=${ client.config.clientId }&permissions=${ client.config.permissions }&scope=bot%20applications.commands)`,
125-
});
126-
await iter.update({
127-
embeds: [helpEmbed],
128-
components: [getButtons(pageNo)],
129-
fetchReply: true,
130-
});
131-
});
132-
});
13+
.setName("help")
14+
.setDescription("Shows this list")
15+
.setRun(async (client, interaction) => {
16+
await interaction.deferReply().catch((_) => {});
17+
// map the commands name and description to the embed
18+
const commands = await LoadCommands().then((cmds) => {
19+
return [].concat(cmds.slash) /*.concat(cmds.context)*/;
20+
});
21+
// from commands remove the ones that have "null" in the description
22+
const filteredCommands = commands.filter(
23+
(cmd) => cmd.description != "null"
24+
);
25+
//console.log(filteredCommands);
26+
const totalCmds = filteredCommands.length;
27+
let maxPages = Math.ceil(totalCmds / client.config.helpCmdPerPage);
28+
29+
// if git exists, then get commit hash
30+
let gitHash = "";
31+
try {
32+
gitHash = require("child_process")
33+
.execSync("git rev-parse --short HEAD")
34+
.toString()
35+
.trim();
36+
} catch (e) {
37+
// do nothing
38+
gitHash = "unknown";
39+
}
40+
41+
// default Page No.
42+
let pageNo = 0;
43+
44+
const helpEmbed = new MessageEmbed()
45+
.setColor(client.config.embedColor)
46+
.setAuthor({
47+
name: `Commands of ${client.user.username}`,
48+
iconURL: client.config.iconURL,
49+
})
50+
.setTimestamp()
51+
.setFooter({ text: `Page ${pageNo + 1} / ${maxPages}` });
52+
53+
// initial temporary array
54+
var tempArray = filteredCommands.slice(
55+
pageNo * client.config.helpCmdPerPage,
56+
pageNo * client.config.helpCmdPerPage + client.config.helpCmdPerPage
57+
);
58+
59+
tempArray.forEach((cmd) => {
60+
helpEmbed.addFields({ name: cmd.name, value: cmd.description });
61+
});
62+
helpEmbed.addFields({
63+
name: "Credits",
64+
value:
65+
`Discord Music Bot Version: v${
66+
require("../../package.json").version
67+
}; Build: ${gitHash}` +
68+
"\n" +
69+
`[✨ Support Server](${client.config.supportServer}) | [Issues](${client.config.Issues}) | [Source](https://github.com/SudhanPlayz/Discord-MusicBot/tree/v5) | [Invite Me](https://discord.com/oauth2/authorize?client_id=${client.config.clientId}&permissions=${client.config.permissions}&scope=bot%20applications.commands)`,
70+
});
71+
72+
// Construction of the buttons for the embed
73+
const getButtons = (pageNo) => {
74+
return new MessageActionRow().addComponents(
75+
new MessageButton()
76+
.setCustomId("help_cmd_but_2_app")
77+
.setEmoji("◀️")
78+
.setStyle("PRIMARY")
79+
.setDisabled(pageNo == 0),
80+
new MessageButton()
81+
.setCustomId("help_cmd_but_1_app")
82+
.setEmoji("▶️")
83+
.setStyle("PRIMARY")
84+
.setDisabled(pageNo == maxPages - 1)
85+
);
86+
};
87+
88+
const tempMsg = await interaction.editReply({
89+
embeds: [helpEmbed],
90+
components: [getButtons(pageNo)],
91+
fetchReply: true,
92+
});
93+
const collector = tempMsg.createMessageComponentCollector({
94+
time: 600000,
95+
componentType: "BUTTON",
96+
});
97+
98+
collector.on("collect", async (iter) => {
99+
if (iter.customId === "help_cmd_but_1_app") {
100+
pageNo++;
101+
} else if (iter.customId === "help_cmd_but_2_app") {
102+
pageNo--;
103+
}
104+
105+
helpEmbed.fields = [];
106+
107+
var tempArray = filteredCommands.slice(
108+
pageNo * client.config.helpCmdPerPage,
109+
pageNo * client.config.helpCmdPerPage + client.config.helpCmdPerPage
110+
);
111+
112+
tempArray.forEach((cmd) => {
113+
//console.log(cmd);
114+
helpEmbed
115+
.addFields({ name: cmd.name, value: cmd.description })
116+
.setFooter({ text: `Page ${pageNo + 1} / ${maxPages}` });
117+
});
118+
helpEmbed.addFields({
119+
name: "Credits",
120+
value:
121+
`Discord Music Bot Version: v${
122+
require("../../package.json").version
123+
}; Build: ${gitHash}` +
124+
"\n" +
125+
`[✨ Support Server](${client.config.supportServer}) | [Issues](${client.config.Issues}) | [Source](https://github.com/SudhanPlayz/Discord-MusicBot/tree/v5) | [Invite Me](https://discord.com/oauth2/authorize?client_id=${client.config.clientId}&permissions=${client.config.permissions}&scope=bot%20applications.commands)`,
126+
});
127+
await iter.update({
128+
embeds: [helpEmbed],
129+
components: [getButtons(pageNo)],
130+
fetchReply: true,
131+
});
132+
});
133+
});
133134

134135
module.exports = command;

0 commit comments

Comments
 (0)