From 7f575ce617011dfe72fab73267b4fbd1a29d6628 Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Mon, 11 Jul 2022 14:43:59 +0300 Subject: [PATCH] defer replies to all commands to avoid timeouts --- src/structure/components/commands/utility/Poll.js | 2 +- src/structure/components/observers/CommandHandler.js | 5 ++++- src/structure/interfaces/commands/SettingsCommand.js | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/structure/components/commands/utility/Poll.js b/src/structure/components/commands/utility/Poll.js index acf3679..77c9eb6 100644 --- a/src/structure/components/commands/utility/Poll.js +++ b/src/structure/components/commands/utility/Poll.js @@ -53,7 +53,7 @@ class PollCommand extends SlashCommand { if (subcommand.name === 'create') { - await invoker.deferReply(); + // await invoker.deferReply(); const questions = []; const _channel = channel?.value || invoker.channel; diff --git a/src/structure/components/observers/CommandHandler.js b/src/structure/components/observers/CommandHandler.js index d4b9499..02e0ddb 100644 --- a/src/structure/components/observers/CommandHandler.js +++ b/src/structure/components/observers/CommandHandler.js @@ -76,13 +76,14 @@ class CommandHandler extends Observer { emoji: 'failure', ephemeral: true }); + await invoker.deferReply(); const inhibitors = await this._handleInhibitors(invoker); if(inhibitors.length) return this._generateError(invoker, { type: 'inhibitor', ...inhibitors[0] }); const response = await this._parseInteraction(interaction, command); if (await this._parseResponse(invoker, response)) return; - try { + try { // Temp logging await this._executeCommand(invoker, response.options); } catch (err) { this.logger.error(`_executeCommand errored:\nCommand: ${invoker.command.name}\nOptions:\n${Object.keys(response.options).map((key) => `[${key}: ${response.options[key]._rawValue}]`).join('\n')}\n${err.stack}`); @@ -130,6 +131,8 @@ class CommandHandler extends Observer { } async _executeCommand(invoker, options) { + // TODO defer all replies -- need to go through all commands to ensure they're not deferrign them to avoid errors + // Why? Occasionally some interacitons don't complete in time due to taking longer than normal to reach the bot -- unsure if deferring all replies will fix it let response = null; const now = Date.now(); diff --git a/src/structure/interfaces/commands/SettingsCommand.js b/src/structure/interfaces/commands/SettingsCommand.js index 2e3ecc9..c6fcd2e 100644 --- a/src/structure/interfaces/commands/SettingsCommand.js +++ b/src/structure/interfaces/commands/SettingsCommand.js @@ -97,7 +97,7 @@ class SettingsCommand extends SlashCommand { }); } - await invoker.deferReply(); + // await invoker.deferReply(); const settings = await guild.settings(); if (!Object.keys(opts).length && this.subcommand(subcommand.name).options.length) return this._showSetting(invoker, setting);