Skip to content

Commit e6c4607

Browse files
committed
possible final pre-release
1 parent b3e08d1 commit e6c4607

2 files changed

Lines changed: 27 additions & 19 deletions

File tree

index.js

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { Client, REST } = require("discord.js");
1+
const { Client, REST, Collection, Routes } = require("discord.js");
22
const { readdirSync } = require("node:fs");
33
const path = require("node:path");
44

@@ -167,7 +167,7 @@ class cDClient extends Client {
167167

168168
let clientGuilds = [];
169169

170-
if (!this.isReady()) {
170+
if (!this.isReady() || this.ws.status != 5) {
171171
// Wait for the guilds to cache before continuing
172172
while (!this.guilds.cache.size) {
173173
await new Promise((resolve) =>
@@ -228,42 +228,50 @@ class cDClient extends Client {
228228
*
229229
* @param {string} command The commands's name or ID
230230
* @param {string | null} guildId The guild's ID to delete the command in (not needed for a global command)
231-
* @returns {Promise<void>}
231+
* @param {Collection | null} commands The command-map like explained [in the guide](https://discordjs.guide/creating-your-bot/command-handling). This is important when using only the name of the command (the command name needs to be associated with the command id)
232+
* @returns {Promise<boolean>} `true` if the operation was successfull. Otherwise an error will be raised.
232233
*/
233-
async deleteCommand(command, guildId = null) {
234-
if (!this.isReady()) {
235-
console.error("The client must be logged in!");
236-
return;
234+
async deleteCommand(command, guildId = null, commands = new Collection()) {
235+
if (!this.isReady() || !this.ws.status == 0) {
236+
throw new Error("The client must be logged in!");
237237
} else if (guildId && !/^\d+$/i.test(guildId)) {
238-
console.error("The guildId is invalid! Must be a numerous string.");
239-
return;
238+
throw new Error(
239+
"The guildId is invalid! Must be a numerous string."
240+
);
240241
}
241242

242243
try {
243244
if (/^\d+$/i.test(command)) {
244245
await this.application.commands.delete(command, guildId);
245246
} else {
246-
const theCommand =
247-
this.application.commands.cache.get(command) ??
248-
(await this.application.commands.fetch({
249-
guildId: guildId,
250-
cache: true,
251-
}));
247+
let theCommand = commands.find((cmd) => cmd.name === command);
248+
if (!theCommand) {
249+
const commands = await this.rest.get(
250+
Routes.applicationGuildCommands(
251+
this.application.id,
252+
guildId
253+
)
254+
);
255+
256+
theCommand = commands.find((cmd) => cmd.name === command);
257+
}
252258

253259
if (!theCommand) {
254-
console.error(
260+
throw new Error(
255261
`❌ Command '${command}' not found in guild '${guildId}'`
256262
);
257-
return;
258263
}
259264

260265
await this.application.commands.delete(theCommand.id, guildId);
261266
}
262267
} catch (err) {
263268
console.error(
264-
`❌ Error while deleting a command in guild '${guildId}'`,
269+
`❌ Error while deleting command '${command}' in guild '${guildId}':`,
265270
err
266271
);
272+
throw new Error(
273+
`Error while deleting command '${command}' in guild '${guildId}'`
274+
);
267275
}
268276
return;
269277
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "djs-command-deployer",
3-
"version": "0.9.3",
3+
"version": "0.10.0",
44
"description": "",
55
"main": "./index.js",
66
"scripts": { },

0 commit comments

Comments
 (0)