From 7cd00ed6450da48911f06cbc27b13828e7a8de06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Thu, 8 Jun 2023 05:27:28 +0300 Subject: [PATCH] Handling missing access to guilds in commands.ts --- src/client/commands.ts | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/client/commands.ts b/src/client/commands.ts index 87244c1..5874489 100644 --- a/src/client/commands.ts +++ b/src/client/commands.ts @@ -35,18 +35,22 @@ export default async function commands(client: RadioClient) { for(const command of commands){ let guilds = await client.guilds.fetch(); guilds.forEach(async (guild: { id: Snowflake; name: string; }) => { - if(!client.application) return; - client.application.commands.create({ - name: command.name, - description: command.description, - options: command.options || [] - }, guild.id); - client.funcs.logger('Application Commands', 'Guild: ' + guild.id + " (" + guild.name + ") \n" + 'Command: ' + command.name); + try { + if(!client.application) return; + await client.application.commands.create({ + name: command.name, + description: command.description, + options: command.options || [] + }, guild.id); + client.funcs.logger('Application Commands', 'Guild: ' + guild.id + " (" + guild.name + ") \n" + 'Command: ' + command.name); + } catch(DiscordAPIError) { + client.funcs.logger('Application Commands', 'Guild: ' + guild.id + " (" + guild.name + ") [FAILED] \n" + 'Command: ' + command.name); + } }); } } else { for(const command of commands){ - client.application.commands.create({ + await client.application.commands.create({ name: command.name, description: command.description, options: command.options || [] @@ -57,8 +61,11 @@ export default async function commands(client: RadioClient) { let guilds = await client.guilds.fetch(); guilds.forEach(async (guild: { id: Snowflake; }) => { - if(!client.application) return; - client.application.commands.set([], guild.id); + try { + if(!client.application) return; + await client.application.commands.set([], guild.id); + } catch (DiscordAPIError){ + } }); } client.funcs.logger('Application Commands', 'Successfully reloaded application (/) commands.' + "\n");