Skip to content

Commit 30b14ef

Browse files
committed
jsdoc fixes for deleteCommand and restructuring
1 parent 85fb21b commit 30b14ef

18 files changed

Lines changed: 2355 additions & 25 deletions

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,6 @@ dist
128128
.yarn/build-state.yml
129129
.yarn/install-state.gz
130130
.pnp.*
131+
132+
# tests
133+
tests

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,18 +119,18 @@ module.exports = {
119119
async run(interaction) {
120120
const serverId = ctx.options.getString("server-id");
121121
const command = ctx.options.getString("command");
122-
await interaction.deferReply({ ephemeral: true })
122+
await interaction.deferReply({ ephemeral: true }); // Defer to remove the risk of not responding in time
123123
try {
124-
await interaction.client.deleteGuildCommand(command, serverId);
124+
await interaction.client.deleteCommand(command, serverId);
125125
} catch (err) {
126126
console.error("Command not deleted due to", err);
127127
return await interaction.editReply({
128128
embeds: [
129129
new EmbedBuilder()
130130
.setTitle("❌ Command not deleted due to an error")
131-
.setDescription('```' + err + '```')
132-
.setColor(0xee0000);
133-
]
131+
.setDescription("```" + err + "```")
132+
.setColor(0xee0000),
133+
],
134134
});
135135
}
136136
await interaction.editReply("✅ Command deleted");

index.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,7 @@ const DEFAULT_OPTS = {
1313
/**
1414
* A Discord Client, that is basically [discord.js' ``Client``](https://discord.js.org/docs/packages/discord.js/main/Client:Class) but with two functions added for command handling.
1515
*/
16-
module.exports = class cDClient extends Client {
17-
checkForCredentials({ token }) {
18-
if (!(this.token || token || this.isReady())) {
19-
console.error(
20-
"Either token must be given or the client must be logged in!"
21-
);
22-
return false;
23-
}
24-
return true;
25-
}
26-
16+
class cDClient extends Client {
2717
/**
2818
* Create, update and delete global and guild application commands.
2919
*
@@ -35,7 +25,13 @@ module.exports = class cDClient extends Client {
3525
* @param {DEFAULT_OPTS} logOptions Whether to log what command was ignored, created, updated or deleted
3626
*/
3727
async deployCommands(folderPath, token = null, logOptions = DEFAULT_OPTS) {
38-
if (this.checkForCredentials({ token })) return;
28+
if (!(this.token || token || this.isReady())) {
29+
console.error(
30+
"Either token must be given or the client must be logged in!"
31+
);
32+
return;
33+
}
34+
3935
if (logOptions.noLogs) {
4036
logOptions.ignored = false;
4137
logOptions.created = false;
@@ -228,9 +224,9 @@ module.exports = class cDClient extends Client {
228224
}
229225

230226
/**
231-
* Delete an application command by its name or ID. **The client needs to be logged in!**
227+
* Shortcut method to delete an application command by its name or ID. **The client needs to be logged in!**
232228
*
233-
* @param {string} command The commands's name or ID | the name will be parsed first
229+
* @param {string} command The commands's name or ID
234230
* @param {string | null} guildId The guild's ID to delete the command in (not needed for a global command)
235231
* @returns {Promise<void>}
236232
*/
@@ -273,6 +269,8 @@ module.exports = class cDClient extends Client {
273269
}
274270
};
275271

272+
module.exports = cDClient;
273+
276274
function deepEqual(obj1, obj2) {
277275
if (obj1 === obj2) {
278276
return true;

node_modules/.package-lock.json

Lines changed: 14 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)