From 0f0c3eb6813391917c604629ae0523da3f35f012 Mon Sep 17 00:00:00 2001 From: "Federico \"fuji97\" Rapetti" Date: Thu, 13 Jan 2022 12:59:18 +0100 Subject: [PATCH] Wrap guild-wise command set code in a Promise.all() to correctly wait the API to resolve --- src/bot.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/bot.ts b/src/bot.ts index 74b56d8..cb10d1b 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -13,6 +13,7 @@ import Config from './services/config.js'; import {generateDependencyReport} from '@discordjs/voice'; import {REST} from '@discordjs/rest'; import {Routes} from 'discord-api-types/v9'; +import {Promise} from 'bluebird'; @injectable() export default class { @@ -133,12 +134,14 @@ export default class { ); } else { // If development, set commands guild-wide - this.client.guilds.cache.each(async guild => { - await rest.put( - Routes.applicationGuildCommands(this.client.user!.id, guild.id), - {body: this.commandsByName.map(command => command.slashCommand ? command.slashCommand.toJSON() : null)}, - ); - }); + await Promise.all( + this.client.guilds.cache.map(async guild => { + await rest.put( + Routes.applicationGuildCommands(this.client.user!.id, guild.id), + {body: this.commandsByName.map(command => command.slashCommand ? command.slashCommand.toJSON() : null)}, + ); + }), + ); } spinner.succeed(`Ready! Invite the bot with https://discordapp.com/oauth2/authorize?client_id=${this.client.user?.id ?? ''}&scope=bot%20applications.commands&permissions=2184236096`);