Skip to content

Commit 7cfd7b9

Browse files
committed
fix minor bug that guilds couldn't be checked
1 parent e140f2c commit 7cfd7b9

2 files changed

Lines changed: 21 additions & 28 deletions

File tree

index.js

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

@@ -165,10 +165,11 @@ class cDClient extends Client {
165165
if (privateCommands.length) {
166166
// TODO: Add support for sharding
167167

168-
let clientGuilds = [];
168+
let clientGuilds = this.guilds.cache;
169169

170-
if (!this.isReady() || this.ws.status != 5) {
170+
if (!this.isReady() || !this.guilds.cache.size) {
171171
// Wait for the guilds to cache before continuing
172+
console.log(this.guilds.cache.size);
172173
while (!this.guilds.cache.size) {
173174
await new Promise((resolve) =>
174175
setTimeout(resolve, 1000)
@@ -228,50 +229,42 @@ class cDClient extends Client {
228229
*
229230
* @param {string} command The commands's name or ID
230231
* @param {string | null} guildId The guild's ID to delete the command in (not needed for a global command)
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.
232+
* @returns {Promise<void>}
233233
*/
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!");
234+
async deleteCommand(command, guildId = null) {
235+
if (!this.isReady()) {
236+
console.error("The client must be logged in!");
237+
return;
237238
} else if (guildId && !/^\d+$/i.test(guildId)) {
238-
throw new Error(
239-
"The guildId is invalid! Must be a numerous string."
240-
);
239+
console.error("The guildId is invalid! Must be a numerous string.");
240+
return;
241241
}
242242

243243
try {
244244
if (/^\d+$/i.test(command)) {
245245
await this.application.commands.delete(command, guildId);
246246
} else {
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-
}
247+
const theCommand =
248+
this.application.commands.cache.get(command) ??
249+
(await this.application.commands.fetch({
250+
guildId: guildId,
251+
cache: true,
252+
}));
258253

259254
if (!theCommand) {
260-
throw new Error(
255+
console.error(
261256
`❌ Command '${command}' not found in guild '${guildId}'`
262257
);
258+
return;
263259
}
264260

265261
await this.application.commands.delete(theCommand.id, guildId);
266262
}
267263
} catch (err) {
268264
console.error(
269-
`❌ Error while deleting command '${command}' in guild '${guildId}':`,
265+
`❌ Error while deleting a command in guild '${guildId}'`,
270266
err
271267
);
272-
throw new Error(
273-
`Error while deleting command '${command}' in guild '${guildId}'`
274-
);
275268
}
276269
return;
277270
}

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": "1.0.0",
3+
"version": "1.0.1",
44
"description": "",
55
"main": "./index.js",
66
"scripts": { },

0 commit comments

Comments
 (0)