|
1 | | -const { Client, REST, Collection, Routes } = require("discord.js"); |
| 1 | +const { Client, REST } = require("discord.js"); |
2 | 2 | const { readdirSync } = require("node:fs"); |
3 | 3 | const path = require("node:path"); |
4 | 4 |
|
@@ -165,10 +165,11 @@ class cDClient extends Client { |
165 | 165 | if (privateCommands.length) { |
166 | 166 | // TODO: Add support for sharding |
167 | 167 |
|
168 | | - let clientGuilds = []; |
| 168 | + let clientGuilds = this.guilds.cache; |
169 | 169 |
|
170 | | - if (!this.isReady() || this.ws.status != 5) { |
| 170 | + if (!this.isReady() || !this.guilds.cache.size) { |
171 | 171 | // Wait for the guilds to cache before continuing |
| 172 | + console.log(this.guilds.cache.size); |
172 | 173 | while (!this.guilds.cache.size) { |
173 | 174 | await new Promise((resolve) => |
174 | 175 | setTimeout(resolve, 1000) |
@@ -228,50 +229,42 @@ class cDClient extends Client { |
228 | 229 | * |
229 | 230 | * @param {string} command The commands's name or ID |
230 | 231 | * @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>} |
233 | 233 | */ |
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; |
237 | 238 | } 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; |
241 | 241 | } |
242 | 242 |
|
243 | 243 | try { |
244 | 244 | if (/^\d+$/i.test(command)) { |
245 | 245 | await this.application.commands.delete(command, guildId); |
246 | 246 | } 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 | + })); |
258 | 253 |
|
259 | 254 | if (!theCommand) { |
260 | | - throw new Error( |
| 255 | + console.error( |
261 | 256 | `❌ Command '${command}' not found in guild '${guildId}'` |
262 | 257 | ); |
| 258 | + return; |
263 | 259 | } |
264 | 260 |
|
265 | 261 | await this.application.commands.delete(theCommand.id, guildId); |
266 | 262 | } |
267 | 263 | } catch (err) { |
268 | 264 | console.error( |
269 | | - `❌ Error while deleting command '${command}' in guild '${guildId}':`, |
| 265 | + `❌ Error while deleting a command in guild '${guildId}'`, |
270 | 266 | err |
271 | 267 | ); |
272 | | - throw new Error( |
273 | | - `Error while deleting command '${command}' in guild '${guildId}'` |
274 | | - ); |
275 | 268 | } |
276 | 269 | return; |
277 | 270 | } |
|
0 commit comments