diff --git a/src/common/validation/permissionValidator.ts b/src/common/validation/permissionValidator.ts index f12b237..51e7328 100644 --- a/src/common/validation/permissionValidator.ts +++ b/src/common/validation/permissionValidator.ts @@ -32,7 +32,7 @@ export const checkVoicePermissionJoinAndTalk = async ({ interaction, executionId interaction.type === InteractionType.ApplicationCommand ? interaction.commandName : interaction.customId; if (channel instanceof VoiceChannel && (!channel.joinable || !channel.speakable)) { - await interaction.editReply({ + await interaction.reply({ embeds: [ new EmbedBuilder() .setDescription( @@ -49,7 +49,8 @@ export const checkVoicePermissionJoinAndTalk = async ({ interaction, executionId : interaction.user.username, iconURL: interaction.user.avatarURL() || embedOptions.info.fallbackIconUrl }) - ] + ], + ephemeral: true }); logger.debug( @@ -83,34 +84,29 @@ export const checkChannelPermissionViewable = async ({ interaction, executionId ); try { - // we can still send ephemeral replies in channels we can't view, so sending message to user instead - if (!interaction.deferred && !interaction.replied) { - logger.debug('Interaction was not deferred or replied to yet. Deferring reply as ephemeral.'); - await interaction.deferReply({ ephemeral: true }); - - logger.debug( - 'Sending ephemeral message in channel about insufficient permissions to send message in channel.' - ); - await interaction.editReply({ - embeds: [ - new EmbedBuilder() - .setDescription( - translator('validation.cannotSendMessageInChannel', { - icon: embedOptions.icons.warning, - channel: `<#${channel.id}>` - }) - ) - .setColor(embedOptions.colors.warning) - .setFooter({ - text: - interaction.member instanceof GuildMember - ? interaction.member.nickname || interaction.user.username - : interaction.user.username, - iconURL: interaction.user.avatarURL() || embedOptions.info.fallbackIconUrl + logger.debug( + 'Sending ephemeral message in channel about insufficient permissions to send message in channel.' + ); + await interaction.reply({ + embeds: [ + new EmbedBuilder() + .setDescription( + translator('validation.cannotSendMessageInChannel', { + icon: embedOptions.icons.warning, + channel: `<#${channel.id}>` }) - ] - }); - } + ) + .setColor(embedOptions.colors.warning) + .setFooter({ + text: + interaction.member instanceof GuildMember + ? interaction.member.nickname || interaction.user.username + : interaction.user.username, + iconURL: interaction.user.avatarURL() || embedOptions.info.fallbackIconUrl + }) + ], + ephemeral: true + }); } catch (error) { if (error instanceof Error) { if (error.message == 'The reply to this interaction has already been sent or deferred.') { diff --git a/src/common/validation/queueValidator.ts b/src/common/validation/queueValidator.ts index 487b397..fd03746 100644 --- a/src/common/validation/queueValidator.ts +++ b/src/common/validation/queueValidator.ts @@ -23,7 +23,7 @@ export const checkQueueExists = async ({ interaction, queue, executionId }: Vali interaction.type === InteractionType.ApplicationCommand ? interaction.commandName : interaction.customId; if (!queue) { - await interaction.editReply({ + await interaction.reply({ embeds: [ new EmbedBuilder() .setDescription( @@ -40,7 +40,8 @@ export const checkQueueExists = async ({ interaction, queue, executionId }: Vali : interaction.user.username, iconURL: interaction.user.avatarURL() || embedOptions.info.fallbackIconUrl }) - ] + ], + ephemeral: true }); logger.debug(`User tried to use command '${interactionIdentifier}' but there was no queue.`); @@ -64,7 +65,7 @@ export const checkHistoryExists = async ({ interaction, history, executionId }: interaction.type === InteractionType.ApplicationCommand ? interaction.commandName : interaction.customId; if (!history) { - await interaction.editReply({ + await interaction.reply({ embeds: [ new EmbedBuilder() .setDescription( @@ -81,7 +82,8 @@ export const checkHistoryExists = async ({ interaction, history, executionId }: : interaction.user.username, iconURL: interaction.user.avatarURL() || embedOptions.info.fallbackIconUrl }) - ] + ], + ephemeral: true }); logger.debug(`User tried to use command '${interactionIdentifier}' but there was no history.`); @@ -105,7 +107,7 @@ export const checkQueueCurrentTrack = async ({ interaction, queue, executionId } interaction.type === InteractionType.ApplicationCommand ? interaction.commandName : interaction.customId; if (queue && !queue.currentTrack) { - await interaction.editReply({ + await interaction.reply({ embeds: [ new EmbedBuilder() .setDescription( @@ -122,7 +124,8 @@ export const checkQueueCurrentTrack = async ({ interaction, queue, executionId } : interaction.user.username, iconURL: interaction.user.avatarURL() || embedOptions.info.fallbackIconUrl }) - ] + ], + ephemeral: true }); logger.debug(`User tried to use command '${interactionIdentifier}' but there was no current track.`); @@ -146,7 +149,7 @@ export const checkQueueEmpty = async ({ interaction, queue, executionId }: Valid interaction.type === InteractionType.ApplicationCommand ? interaction.commandName : interaction.customId; if (queue && queue.tracks.data.length === 0) { - await interaction.editReply({ + await interaction.reply({ embeds: [ new EmbedBuilder() .setDescription( @@ -163,7 +166,8 @@ export const checkQueueEmpty = async ({ interaction, queue, executionId }: Valid : interaction.user.username, iconURL: interaction.user.avatarURL() || embedOptions.info.fallbackIconUrl }) - ] + ], + ephemeral: true }); logger.debug(`User tried to use command '${interactionIdentifier}' but there was no tracks in the queue.`); diff --git a/src/common/validation/systemCommandValidator.ts b/src/common/validation/systemCommandValidator.ts index e120e96..d65763d 100644 --- a/src/common/validation/systemCommandValidator.ts +++ b/src/common/validation/systemCommandValidator.ts @@ -24,7 +24,7 @@ export const checkValidGuildId = async ({ interaction, executionId }: ValidatorP interaction.type === InteractionType.ApplicationCommand ? interaction.commandName : interaction.customId; if (interaction.guildId && !systemOptions.systemGuildIds.includes(interaction.guildId)) { - await interaction.editReply({ + await interaction.reply({ embeds: [ new EmbedBuilder() .setDescription( @@ -34,7 +34,8 @@ export const checkValidGuildId = async ({ interaction, executionId }: ValidatorP }) ) .setColor(embedOptions.colors.warning) - ] + ], + ephemeral: true }); logger.debug( diff --git a/src/common/validation/voiceChannelValidator.ts b/src/common/validation/voiceChannelValidator.ts index 764ac48..799f282 100644 --- a/src/common/validation/voiceChannelValidator.ts +++ b/src/common/validation/voiceChannelValidator.ts @@ -22,7 +22,7 @@ export const checkInVoiceChannel = async ({ interaction, executionId }: Validato interaction.type === InteractionType.ApplicationCommand ? interaction.commandName : interaction.customId; if (interaction.member instanceof GuildMember && !interaction.member.voice.channel) { - await interaction.editReply({ + await interaction.reply({ embeds: [ new EmbedBuilder() .setDescription( @@ -35,7 +35,8 @@ export const checkInVoiceChannel = async ({ interaction, executionId }: Validato text: interaction.member.nickname || interaction.user.username, iconURL: interaction.user.avatarURL() || embedOptions.info.fallbackIconUrl }) - ] + ], + ephemeral: true }); logger.debug(`User tried to use command '${interactionIdentifier}' but was not in a voice channel.`); @@ -67,7 +68,7 @@ export const checkSameVoiceChannel = async ({ interaction, queue, executionId }: interaction.member instanceof GuildMember && interaction.member.voice.channel?.id !== queue.dispatcher.channel.id ) { - await interaction.editReply({ + await interaction.reply({ embeds: [ new EmbedBuilder() .setDescription( @@ -81,7 +82,8 @@ export const checkSameVoiceChannel = async ({ interaction, queue, executionId }: text: interaction.member.nickname || interaction.user.username, iconURL: interaction.user.avatarURL() || embedOptions.info.fallbackIconUrl }) - ] + ], + ephemeral: true }); logger.debug(`User tried to use command '${interactionIdentifier}' but was not in the same voice channel.`); diff --git a/src/handlers/interactionCommandHandler.ts b/src/handlers/interactionCommandHandler.ts index d63ef87..78d6e9c 100644 --- a/src/handlers/interactionCommandHandler.ts +++ b/src/handlers/interactionCommandHandler.ts @@ -17,9 +17,6 @@ export const handleCommand = async ( executionId: executionId }); - await interaction.deferReply(); - logger.debug('Interaction deferred.'); - await checkChannelPermissionViewable({ interaction, executionId }); const slashCommand: BaseSlashCommandInteraction = client.slashCommandInteractions!.get( diff --git a/src/handlers/interactionComponentHandler.ts b/src/handlers/interactionComponentHandler.ts index 9147faf..1013ed0 100644 --- a/src/handlers/interactionComponentHandler.ts +++ b/src/handlers/interactionComponentHandler.ts @@ -17,9 +17,6 @@ export const handleComponent = async ( executionId: executionId }); - await interaction.deferReply(); - logger.debug('Interaction deferred.'); - const componentId: string = interactionIdentifier.split('_')[0]; const referenceId: string = interactionIdentifier.split('_')[1]; diff --git a/src/interactions/components/action-pauseresume-button.ts b/src/interactions/components/action-pauseresume-button.ts index 4ebe309..e2b1ad6 100644 --- a/src/interactions/components/action-pauseresume-button.ts +++ b/src/interactions/components/action-pauseresume-button.ts @@ -6,7 +6,7 @@ import { checkQueueCurrentTrack, checkQueueExists } from '../../common/validatio import { checkInVoiceChannel, checkSameVoiceChannel } from '../../common/validation/voiceChannelValidator'; import { TFunction } from 'i18next'; import { useServerTranslator } from '../../common/utils/localeUtil'; -import { formatRepeatModeDetailed, formatSlashCommand } from '../../common/utils/formattingUtils'; +import { formatRepeatModeDetailed } from '../../common/utils/formattingUtils'; class ActionPauseResumeButton extends BaseComponentInteraction { constructor() { @@ -27,10 +27,6 @@ class ActionPauseResumeButton extends BaseComponentInteraction { checkQueueCurrentTrack ]); - if (!queue || (queue.tracks.data.length === 0 && !queue.currentTrack)) { - return await this.handleNoQueue(interaction, translator); - } - if (queue.currentTrack!.id !== referenceId) { return await this.handleAlreadySkipped(interaction, translator); } @@ -48,24 +44,8 @@ class ActionPauseResumeButton extends BaseComponentInteraction { return await this.handleSuccess(interaction, currentTrack, queue, translator); } - private async handleNoQueue(interaction: MessageComponentInteraction, translator: TFunction) { - return await interaction.editReply({ - embeds: [ - new EmbedBuilder() - .setDescription( - translator('validation.queueNoCurrentTrack', { - icon: this.embedOptions.icons.warning, - playCommand: formatSlashCommand('play', translator) - }) - ) - .setColor(this.embedOptions.colors.warning) - ], - components: [] - }); - } - private async handleAlreadySkipped(interaction: MessageComponentInteraction, translator: TFunction) { - return await interaction.editReply({ + return await interaction.reply({ embeds: [ new EmbedBuilder() .setDescription( @@ -75,7 +55,8 @@ class ActionPauseResumeButton extends BaseComponentInteraction { ) .setColor(this.embedOptions.colors.warning) ], - components: [] + components: [], + ephemeral: true }); } @@ -98,7 +79,7 @@ class ActionPauseResumeButton extends BaseComponentInteraction { .setThumbnail(track.thumbnail) .setColor(this.embedOptions.colors.success); - return await interaction.editReply({ + return await interaction.reply({ embeds: [successEmbed], components: [] }); diff --git a/src/interactions/components/action-previous-button.ts b/src/interactions/components/action-previous-button.ts index bf423e2..87d2260 100644 --- a/src/interactions/components/action-previous-button.ts +++ b/src/interactions/components/action-previous-button.ts @@ -29,10 +29,6 @@ class ActionPreviousButton extends BaseComponentInteraction { checkQueueCurrentTrack ]); - if (!queue || (queue.tracks.data.length === 0 && !queue.currentTrack)) { - return await this.handleNoQueue(interaction, translator); - } - if (queue.currentTrack!.id !== referenceId) { return await this.handleAlreadySkipped(interaction, translator); } @@ -76,24 +72,8 @@ class ActionPreviousButton extends BaseComponentInteraction { }); } - private async handleNoQueue(interaction: MessageComponentInteraction, translator: TFunction) { - return await interaction.editReply({ - embeds: [ - new EmbedBuilder() - .setDescription( - translator('validation.queueNoCurrentTrack', { - icon: this.embedOptions.icons.warning, - playCommand: formatSlashCommand('play', translator) - }) - ) - .setColor(this.embedOptions.colors.warning) - ], - components: [] - }); - } - private async handleAlreadySkipped(interaction: MessageComponentInteraction, translator: TFunction) { - return await interaction.editReply({ + return await interaction.reply({ embeds: [ new EmbedBuilder() .setDescription( @@ -103,7 +83,8 @@ class ActionPreviousButton extends BaseComponentInteraction { ) .setColor(this.embedOptions.colors.warning) ], - components: [] + components: [], + ephemeral: true }); } @@ -123,7 +104,7 @@ class ActionPreviousButton extends BaseComponentInteraction { .setThumbnail(recoveredTrack.thumbnail) .setColor(this.embedOptions.colors.success); - return await interaction.editReply({ + return await interaction.reply({ embeds: [successEmbed], components: [] }); diff --git a/src/interactions/components/action-skip-button.ts b/src/interactions/components/action-skip-button.ts index 9635a83..05562e3 100644 --- a/src/interactions/components/action-skip-button.ts +++ b/src/interactions/components/action-skip-button.ts @@ -6,7 +6,7 @@ import { checkQueueCurrentTrack, checkQueueExists } from '../../common/validatio import { checkInVoiceChannel, checkSameVoiceChannel } from '../../common/validation/voiceChannelValidator'; import { TFunction } from 'i18next'; import { useServerTranslator } from '../../common/utils/localeUtil'; -import { formatRepeatModeDetailed, formatSlashCommand } from '../../common/utils/formattingUtils'; +import { formatRepeatModeDetailed } from '../../common/utils/formattingUtils'; class ActionSkipButton extends BaseComponentInteraction { constructor() { @@ -27,10 +27,6 @@ class ActionSkipButton extends BaseComponentInteraction { checkQueueCurrentTrack ]); - if (!queue || (queue.tracks.data.length === 0 && !queue.currentTrack)) { - return await this.handleNoQueue(interaction, translator); - } - if (queue.currentTrack!.id !== referenceId) { return await this.handleAlreadySkipped(interaction, translator); } @@ -43,24 +39,8 @@ class ActionSkipButton extends BaseComponentInteraction { return await this.handleSuccess(interaction, skippedTrack, queue, translator); } - private async handleNoQueue(interaction: MessageComponentInteraction, translator: TFunction) { - return await interaction.editReply({ - embeds: [ - new EmbedBuilder() - .setDescription( - translator('validation.queueNoCurrentTrack', { - icon: this.embedOptions.icons.warning, - playCommand: formatSlashCommand('play', translator) - }) - ) - .setColor(this.embedOptions.colors.warning) - ], - components: [] - }); - } - private async handleAlreadySkipped(interaction: MessageComponentInteraction, translator: TFunction) { - return await interaction.editReply({ + return await interaction.reply({ embeds: [ new EmbedBuilder() .setDescription( @@ -70,7 +50,8 @@ class ActionSkipButton extends BaseComponentInteraction { ) .setColor(this.embedOptions.colors.warning) ], - components: [] + components: [], + ephemeral: true }); } @@ -93,7 +74,7 @@ class ActionSkipButton extends BaseComponentInteraction { .setThumbnail(skippedTrack.thumbnail) .setColor(this.embedOptions.colors.success); - return await interaction.editReply({ + return await interaction.reply({ embeds: [successEmbed], components: [] }); diff --git a/src/interactions/components/filters-disable-button.ts b/src/interactions/components/filters-disable-button.ts index c710d56..274a102 100644 --- a/src/interactions/components/filters-disable-button.ts +++ b/src/interactions/components/filters-disable-button.ts @@ -28,7 +28,7 @@ class FiltersDisableButtonComponent extends BaseComponentInteraction { this.resetFilters(queue, logger); logger.debug('Responding with success embed.'); - return await interaction.editReply({ + return await interaction.reply({ embeds: [ new EmbedBuilder() .setAuthor(this.getEmbedUserAuthor(interaction)) diff --git a/src/interactions/components/filters-select-menu.ts b/src/interactions/components/filters-select-menu.ts index 2d237f5..e7ed46b 100644 --- a/src/interactions/components/filters-select-menu.ts +++ b/src/interactions/components/filters-select-menu.ts @@ -1,6 +1,6 @@ import config from 'config'; import { BiquadFilters, EqualizerConfigurationPreset, GuildQueue, QueueFilters, useQueue } from 'discord-player'; -import { EmbedBuilder, Message, StringSelectMenuInteraction } from 'discord.js'; +import { EmbedBuilder, InteractionResponse, StringSelectMenuInteraction } from 'discord.js'; import { Logger } from 'pino'; import { BaseComponentInteraction } from '../../common/classes/interactions'; import { @@ -84,7 +84,7 @@ class FiltersSelectMenuComponent extends BaseComponentInteraction { queue: GuildQueue, filterType: string, translator: TFunction - ): Promise { + ): Promise> { this.addFfmpegNormalizerIfRequired(selectMenuInteraction); this.toggleFfmpegFilters(selectMenuInteraction, queue, logger); @@ -98,7 +98,7 @@ class FiltersSelectMenuComponent extends BaseComponentInteraction { queue: GuildQueue, filterType: string, translator: TFunction - ): Promise { + ): Promise> { this.toggleBiquadFilter(selectMenuInteraction, queue, logger); logger.debug('Responding with success embed.'); @@ -111,7 +111,7 @@ class FiltersSelectMenuComponent extends BaseComponentInteraction { queue: GuildQueue, filterType: string, translator: TFunction - ): Promise { + ): Promise> { this.toggleEqualizerFilter(selectMenuInteraction, queue, logger); logger.debug('Responding with success embed.'); @@ -198,9 +198,9 @@ class FiltersSelectMenuComponent extends BaseComponentInteraction { interaction: StringSelectMenuInteraction, filterType: string, translator: TFunction - ): Promise { + ): Promise> { logger.debug('Responding with success embed.'); - return interaction.editReply({ + return interaction.reply({ embeds: [this.buildSuccessEmbed(interaction, filterType, translator)], components: [] }); @@ -277,9 +277,9 @@ class FiltersSelectMenuComponent extends BaseComponentInteraction { logger: Logger, interaction: StringSelectMenuInteraction, translator: TFunction - ): Promise { + ): Promise> { logger.debug('Responding with success embed.'); - return await interaction.editReply({ + return await interaction.reply({ embeds: [ new EmbedBuilder() .setAuthor(this.getEmbedUserAuthor(interaction)) diff --git a/src/interactions/slashcommands/back.ts b/src/interactions/slashcommands/back.ts index 74e058b..74957f9 100644 --- a/src/interactions/slashcommands/back.ts +++ b/src/interactions/slashcommands/back.ts @@ -73,7 +73,7 @@ class BackCommand extends BaseSlashCommandInteraction { translator: TFunction ) { logger.debug('Specified track position was higher than total tracks.'); - return await interaction.editReply({ + return await interaction.reply({ embeds: [ new EmbedBuilder() .setDescription( @@ -85,7 +85,8 @@ class BackCommand extends BaseSlashCommandInteraction { }) ) .setColor(this.embedOptions.colors.warning) - ] + ], + ephemeral: true }); } @@ -111,7 +112,7 @@ class BackCommand extends BaseSlashCommandInteraction { translator: TFunction ) { logger.debug('No tracks in history.'); - return await interaction.editReply({ + return await interaction.reply({ embeds: [ new EmbedBuilder() .setDescription( @@ -121,7 +122,8 @@ class BackCommand extends BaseSlashCommandInteraction { }) ) .setColor(this.embedOptions.colors.warning) - ] + ], + ephemeral: true }); } @@ -130,7 +132,7 @@ class BackCommand extends BaseSlashCommandInteraction { interaction: ChatInputCommandInteraction, translator: TFunction ) { - return await interaction.editReply({ + return await interaction.reply({ embeds: [ new EmbedBuilder() .setAuthor(this.getEmbedUserAuthor(interaction)) diff --git a/src/interactions/slashcommands/filters.ts b/src/interactions/slashcommands/filters.ts index e7fd27c..949bc11 100644 --- a/src/interactions/slashcommands/filters.ts +++ b/src/interactions/slashcommands/filters.ts @@ -68,6 +68,9 @@ class FiltersCommand extends BaseSlashCommandInteraction { checkQueueCurrentTrack ]); + await interaction.deferReply(); + logger.debug('Interaction deferred.'); + const filterProvider: string = interaction.options.getString('type') || 'ffmpeg'; switch (filterProvider) { diff --git a/src/interactions/slashcommands/help.ts b/src/interactions/slashcommands/help.ts index c3b8df4..3028056 100644 --- a/src/interactions/slashcommands/help.ts +++ b/src/interactions/slashcommands/help.ts @@ -64,7 +64,7 @@ class HelpCommand extends BaseSlashCommandInteraction { }; logger.debug('Responding with info embed.'); - return await interaction.editReply({ + return await interaction.reply({ embeds: [ new EmbedBuilder() .setDescription( diff --git a/src/interactions/slashcommands/history.ts b/src/interactions/slashcommands/history.ts index ea4abf5..54f0d1f 100644 --- a/src/interactions/slashcommands/history.ts +++ b/src/interactions/slashcommands/history.ts @@ -125,7 +125,7 @@ class HistoryCommand extends BaseSlashCommandInteraction { }; logger.debug('Responding with info embed.'); - await interaction.editReply({ + await interaction.reply({ embeds: [ new EmbedBuilder() .setAuthor(this.getEmbedQueueAuthor(interaction, queue, translator)) @@ -169,7 +169,7 @@ class HistoryCommand extends BaseSlashCommandInteraction { logger.debug('History exists but there is no current track.'); logger.debug('Responding with info embed.'); - return await interaction.editReply({ + return await interaction.reply({ embeds: [ new EmbedBuilder() .setAuthor(this.getEmbedQueueAuthor(interaction, queue, translator)) @@ -182,7 +182,8 @@ class HistoryCommand extends BaseSlashCommandInteraction { ) .setFooter(this.getDisplayFullFooterInfo(interaction, history, translator)) .setColor(this.embedOptions.colors.info) - ] + ], + ephemeral: true }); } @@ -196,7 +197,7 @@ class HistoryCommand extends BaseSlashCommandInteraction { logger.debug('Specified page was higher than total pages.'); logger.debug('Responding with warning embed.'); - await interaction.editReply({ + await interaction.reply({ embeds: [ new EmbedBuilder() .setDescription( @@ -207,7 +208,8 @@ class HistoryCommand extends BaseSlashCommandInteraction { }) ) .setColor(this.embedOptions.colors.warning) - ] + ], + ephemeral: true }); return Promise.resolve(); } diff --git a/src/interactions/slashcommands/join.ts b/src/interactions/slashcommands/join.ts index 847cbac..94573a6 100644 --- a/src/interactions/slashcommands/join.ts +++ b/src/interactions/slashcommands/join.ts @@ -22,6 +22,9 @@ class JoinCommand extends BaseSlashCommandInteraction { await this.runValidators({ interaction, executionId }, [checkInVoiceChannel, checkVoicePermissionJoinAndTalk]); + await interaction.deferReply(); + logger.debug('Interaction deferred.'); + const existingQueue = useQueue(interaction.guild!.id); if (existingQueue) { diff --git a/src/interactions/slashcommands/leave.ts b/src/interactions/slashcommands/leave.ts index 985a181..7d78ec0 100644 --- a/src/interactions/slashcommands/leave.ts +++ b/src/interactions/slashcommands/leave.ts @@ -26,6 +26,9 @@ class LeaveCommand extends BaseSlashCommandInteraction { checkQueueExists ]); + await interaction.deferReply(); + logger.debug('Interaction deferred.'); + logger.debug('Deleting queue.'); this.deleteQueue(queue); diff --git a/src/interactions/slashcommands/loop.ts b/src/interactions/slashcommands/loop.ts index a526a3f..9cba7c7 100644 --- a/src/interactions/slashcommands/loop.ts +++ b/src/interactions/slashcommands/loop.ts @@ -2,7 +2,7 @@ import { GuildQueue, QueueRepeatMode, useQueue } from 'discord-player'; import { ChatInputCommandInteraction, EmbedBuilder, - Message, + InteractionResponse, SlashCommandBuilder, SlashCommandIntegerOption } from 'discord.js'; @@ -74,7 +74,7 @@ class LoopCommand extends BaseSlashCommandInteraction { interaction: ChatInputCommandInteraction, currentRepeatMode: QueueRepeatMode, translator: TFunction - ): Promise { + ): Promise> { logger.debug('No repeat mode was provided, responding with current repeat mode.'); const repeatModeEmbedIcon = @@ -82,7 +82,7 @@ class LoopCommand extends BaseSlashCommandInteraction { const repeatModeEmbedName = formatRepeatMode(currentRepeatMode, translator); logger.debug('Responding with info embed.'); - return await interaction.editReply({ + return await interaction.reply({ embeds: [ new EmbedBuilder() .setDescription( @@ -101,11 +101,11 @@ class LoopCommand extends BaseSlashCommandInteraction { interaction: ChatInputCommandInteraction, currentRepeatMode: QueueRepeatMode, translator: TFunction - ): Promise { + ): Promise> { const repeatModeEmbedName = formatRepeatMode(currentRepeatMode, translator); logger.debug(`Loop mode is already set to '${repeatModeEmbedName}'.`); logger.debug('Responding with warning embed.'); - return await interaction.editReply({ + return await interaction.reply({ embeds: [ new EmbedBuilder() .setDescription( @@ -115,7 +115,8 @@ class LoopCommand extends BaseSlashCommandInteraction { }) ) .setColor(this.embedOptions.colors.warning) - ] + ], + ephemeral: true }); } @@ -126,7 +127,7 @@ class LoopCommand extends BaseSlashCommandInteraction { fromRepeatMode: QueueRepeatMode, toRepeatMode: QueueRepeatMode, translator: TFunction - ): Promise { + ): Promise> { const newRepeatModeEmbedName = formatRepeatMode(toRepeatMode, translator); const getChangedRepeatModeEmbedReply = this.getChangedRepeatModeEmbedReply( fromRepeatMode, @@ -138,7 +139,7 @@ class LoopCommand extends BaseSlashCommandInteraction { logger.debug(`Loop mode changed to '${newRepeatModeEmbedName}'.`); logger.debug('Responding with success embed.'); - return await interaction.editReply({ + return await interaction.reply({ embeds: [ new EmbedBuilder() .setAuthor(this.getEmbedUserAuthor(interaction)) diff --git a/src/interactions/slashcommands/lyrics.ts b/src/interactions/slashcommands/lyrics.ts index 0d87da3..8422d85 100644 --- a/src/interactions/slashcommands/lyrics.ts +++ b/src/interactions/slashcommands/lyrics.ts @@ -38,6 +38,9 @@ class LyricsCommand extends BaseSlashCommandInteraction { ]); } + await interaction.deferReply(); + logger.debug('Interaction deferred.'); + const geniusSearchQuery: string = this.getGeniusSearchQuery(logger, query, queue); const [playerSearchResult, geniusLyricsResult] = await Promise.all([ this.getPlayerSearchResult(logger, query), diff --git a/src/interactions/slashcommands/move.ts b/src/interactions/slashcommands/move.ts index e5da5d0..c7e2851 100644 --- a/src/interactions/slashcommands/move.ts +++ b/src/interactions/slashcommands/move.ts @@ -81,7 +81,7 @@ class MoveCommand extends BaseSlashCommandInteraction { translator: TFunction ) { logger.debug('One of the specified track positions was higher than total tracks.'); - return await interaction.editReply({ + return await interaction.reply({ embeds: [ new EmbedBuilder() .setDescription( @@ -94,7 +94,8 @@ class MoveCommand extends BaseSlashCommandInteraction { }) ) .setColor(this.embedOptions.colors.warning) - ] + ], + ephemeral: true }); } @@ -105,7 +106,7 @@ class MoveCommand extends BaseSlashCommandInteraction { toPosition: number, translator: TFunction ) { - return await interaction.editReply({ + return await interaction.reply({ embeds: [ new EmbedBuilder() .setAuthor(this.getEmbedUserAuthor(interaction)) diff --git a/src/interactions/slashcommands/nowplaying.ts b/src/interactions/slashcommands/nowplaying.ts index 1d8988c..ebfad00 100644 --- a/src/interactions/slashcommands/nowplaying.ts +++ b/src/interactions/slashcommands/nowplaying.ts @@ -88,7 +88,7 @@ class NowPlayingCommand extends BaseSlashCommandInteraction { }; logger.debug('Sending info embed with action row components.'); - return await interaction.editReply({ + return await interaction.reply({ embeds: [ new EmbedBuilder() .setAuthor(this.getEmbedQueueAuthor(interaction, queue, translator)) diff --git a/src/interactions/slashcommands/pause.ts b/src/interactions/slashcommands/pause.ts index da0a867..685c9c5 100644 --- a/src/interactions/slashcommands/pause.ts +++ b/src/interactions/slashcommands/pause.ts @@ -32,7 +32,7 @@ class PauseCommand extends BaseSlashCommandInteraction { this.togglePauseState(logger, queue); logger.debug('Responding with success embed.'); - return await interaction.editReply({ + return await interaction.reply({ embeds: [ new EmbedBuilder() .setAuthor(this.getEmbedUserAuthor(interaction)) diff --git a/src/interactions/slashcommands/play.ts b/src/interactions/slashcommands/play.ts index 20cd9ff..fb579ed 100644 --- a/src/interactions/slashcommands/play.ts +++ b/src/interactions/slashcommands/play.ts @@ -43,6 +43,9 @@ class PlayCommand extends BaseSlashCommandInteraction { await this.runValidators({ interaction, executionId }, [checkVoicePermissionJoinAndTalk]); } + await interaction.deferReply(); + logger.debug('Interaction deferred.'); + const player = useMainPlayer()!; const searchQuery = interaction.options.getString('query')!; const transformedQuery = transformQuery({ query: searchQuery, executionId }); diff --git a/src/interactions/slashcommands/queue.ts b/src/interactions/slashcommands/queue.ts index 1abb3b7..9698b4f 100644 --- a/src/interactions/slashcommands/queue.ts +++ b/src/interactions/slashcommands/queue.ts @@ -115,7 +115,7 @@ class QueueCommand extends BaseSlashCommandInteraction { }; logger.debug('Responding with info embed.'); - await interaction.editReply({ + await interaction.reply({ embeds: [ new EmbedBuilder() .setAuthor(this.getEmbedQueueAuthor(interaction, queue, translator)) @@ -160,7 +160,7 @@ class QueueCommand extends BaseSlashCommandInteraction { logger.debug('Queue exists but there is no current track.'); logger.debug('Responding with info embed.'); - return await interaction.editReply({ + return await interaction.reply({ embeds: [ new EmbedBuilder() .setAuthor(this.getEmbedQueueAuthor(interaction, queue, translator)) @@ -173,7 +173,8 @@ class QueueCommand extends BaseSlashCommandInteraction { ) .setFooter(this.getDisplayFullFooterInfo(interaction, queue, translator)) .setColor(this.embedOptions.colors.info) - ] + ], + ephemeral: true }); } @@ -187,7 +188,7 @@ class QueueCommand extends BaseSlashCommandInteraction { logger.debug('Specified page was higher than total pages.'); logger.debug('Responding with warning embed.'); - await interaction.editReply({ + await interaction.reply({ embeds: [ new EmbedBuilder() .setDescription( @@ -198,7 +199,8 @@ class QueueCommand extends BaseSlashCommandInteraction { }) ) .setColor(this.embedOptions.colors.warning) - ] + ], + ephemeral: true }); return Promise.resolve(); } diff --git a/src/interactions/slashcommands/reload.ts b/src/interactions/slashcommands/reload.ts index 896ed39..51ce816 100644 --- a/src/interactions/slashcommands/reload.ts +++ b/src/interactions/slashcommands/reload.ts @@ -27,6 +27,9 @@ class ReloadCommand extends BaseSlashCommandInteraction { await this.runValidators({ interaction, executionId }, [checkValidGuildId]); + await interaction.deferReply(); + logger.debug('Interaction deferred.'); + try { await this.reloadInteractionsAcrossShards(logger, executionId, client!); } catch (error) { diff --git a/src/interactions/slashcommands/remove.ts b/src/interactions/slashcommands/remove.ts index a085007..39752d7 100644 --- a/src/interactions/slashcommands/remove.ts +++ b/src/interactions/slashcommands/remove.ts @@ -134,7 +134,7 @@ class RemoveCommand extends BaseSlashCommandInteraction { logger.debug('Start position is higher than end position.'); logger.debug('Responding with warning embed.'); - await interaction.editReply({ + await interaction.reply({ embeds: [ new EmbedBuilder() .setDescription( @@ -146,7 +146,8 @@ class RemoveCommand extends BaseSlashCommandInteraction { }) ) .setColor(this.embedOptions.colors.warning) - ] + ], + ephemeral: true }); return Promise.resolve(); } @@ -208,7 +209,7 @@ class RemoveCommand extends BaseSlashCommandInteraction { logger.debug(`Removed track '${removedTrack.url}' from queue.`); logger.debug('Responding with success embed.'); - await interaction.editReply({ + await interaction.reply({ embeds: [ new EmbedBuilder() .setAuthor(this.getEmbedUserAuthor(interaction)) @@ -232,7 +233,7 @@ class RemoveCommand extends BaseSlashCommandInteraction { translator: TFunction ) { logger.debug('Responding with warning embed.'); - await interaction.editReply({ + await interaction.reply({ embeds: [ new EmbedBuilder() .setAuthor(this.getEmbedUserAuthor(interaction)) @@ -242,7 +243,8 @@ class RemoveCommand extends BaseSlashCommandInteraction { }) ) .setColor(this.embedOptions.colors.warning) - ] + ], + ephemeral: true }); return Promise.resolve(); } @@ -254,7 +256,7 @@ class RemoveCommand extends BaseSlashCommandInteraction { translator: TFunction ) { logger.debug('Responding with success embed.'); - await interaction.editReply({ + await interaction.reply({ embeds: [ new EmbedBuilder() .setAuthor(this.getEmbedUserAuthor(interaction)) @@ -280,7 +282,7 @@ class RemoveCommand extends BaseSlashCommandInteraction { logger.debug('Specified track position is higher than total tracks.'); logger.debug('Responding with warning embed.'); - await interaction.editReply({ + await interaction.reply({ embeds: [ new EmbedBuilder() .setDescription( @@ -292,7 +294,8 @@ class RemoveCommand extends BaseSlashCommandInteraction { }) ) .setColor(this.embedOptions.colors.warning) - ] + ], + ephemeral: true }); return Promise.resolve(); } diff --git a/src/interactions/slashcommands/seek.ts b/src/interactions/slashcommands/seek.ts index 997d6f2..272c8f7 100644 --- a/src/interactions/slashcommands/seek.ts +++ b/src/interactions/slashcommands/seek.ts @@ -33,6 +33,9 @@ class SeekCommand extends BaseSlashCommandInteraction { checkQueueCurrentTrack ]); + await interaction.deferReply(); + logger.debug('Interaction deferred.'); + const durationInputSplit: string[] = interaction.options.getString('duration')!.split(':'); const formattedDurationString: string = this.parseDurationArray(durationInputSplit); diff --git a/src/interactions/slashcommands/settings.ts b/src/interactions/slashcommands/settings.ts index 8d71117..f53ae9b 100644 --- a/src/interactions/slashcommands/settings.ts +++ b/src/interactions/slashcommands/settings.ts @@ -42,6 +42,9 @@ class SettingsCommand extends BaseSlashCommandInteraction { const logger = this.getLogger(this.name, executionId, interaction); const translator = useServerTranslator(interaction); + await interaction.deferReply(); + logger.debug('Interaction deferred.'); + const subcommand = interaction.options.getSubcommand(); switch (subcommand) { diff --git a/src/interactions/slashcommands/shards.ts b/src/interactions/slashcommands/shards.ts index 2183db1..d46d33e 100644 --- a/src/interactions/slashcommands/shards.ts +++ b/src/interactions/slashcommands/shards.ts @@ -43,6 +43,9 @@ class ShardsCommand extends BaseSlashCommandInteraction { await this.runValidators({ interaction, executionId }, [checkValidGuildId]); + await interaction.deferReply(); + logger.debug('Interaction deferred.'); + const shardInfoList: ShardInfo[] = await this.fetchShardInfo( client!, logger, diff --git a/src/interactions/slashcommands/shuffle.ts b/src/interactions/slashcommands/shuffle.ts index 15ec8ed..746ab1c 100644 --- a/src/interactions/slashcommands/shuffle.ts +++ b/src/interactions/slashcommands/shuffle.ts @@ -31,7 +31,7 @@ class ShuffleCommand extends BaseSlashCommandInteraction { logger.debug('Shuffled queue tracks.'); logger.debug('Responding with success embed.'); - return await interaction.editReply({ + return await interaction.reply({ embeds: [ new EmbedBuilder() .setAuthor(this.getEmbedUserAuthor(interaction)) diff --git a/src/interactions/slashcommands/skip.ts b/src/interactions/slashcommands/skip.ts index 1520593..d5b1d71 100644 --- a/src/interactions/slashcommands/skip.ts +++ b/src/interactions/slashcommands/skip.ts @@ -73,7 +73,7 @@ class SkipCommand extends BaseSlashCommandInteraction { translator: TFunction ) { logger.debug('Specified track position was higher than total tracks.'); - return await interaction.editReply({ + return await interaction.reply({ embeds: [ new EmbedBuilder() .setDescription( @@ -85,7 +85,8 @@ class SkipCommand extends BaseSlashCommandInteraction { }) ) .setColor(this.embedOptions.colors.warning) - ] + ], + ephemeral: true }); } @@ -111,7 +112,7 @@ class SkipCommand extends BaseSlashCommandInteraction { translator: TFunction ) { logger.debug('No tracks in queue and no current track.'); - return await interaction.editReply({ + return await interaction.reply({ embeds: [ new EmbedBuilder() .setDescription( @@ -121,7 +122,8 @@ class SkipCommand extends BaseSlashCommandInteraction { }) ) .setColor(this.embedOptions.colors.warning) - ] + ], + ephemeral: true }); } @@ -131,7 +133,7 @@ class SkipCommand extends BaseSlashCommandInteraction { queue: GuildQueue, translator: TFunction ) { - return await interaction.editReply({ + return await interaction.reply({ embeds: [ new EmbedBuilder() .setAuthor(this.getEmbedUserAuthor(interaction)) diff --git a/src/interactions/slashcommands/status.ts b/src/interactions/slashcommands/status.ts index 338d9da..7a80f7e 100644 --- a/src/interactions/slashcommands/status.ts +++ b/src/interactions/slashcommands/status.ts @@ -31,6 +31,9 @@ class StatusCommand extends BaseSlashCommandInteraction { const logger = this.getLogger(this.name, executionId, interaction); const translator = useServerTranslator(interaction); + await interaction.deferReply(); + logger.debug('Interaction deferred.'); + const [botStatisticsEmbedString, playerStatisticsEmbedString, systemStatusEmbedString] = await Promise.all([ getBotStatistics(client!, version, translator), getPlayerStatistics(client!, translator), diff --git a/src/interactions/slashcommands/stop.ts b/src/interactions/slashcommands/stop.ts index 4c99128..dabc773 100644 --- a/src/interactions/slashcommands/stop.ts +++ b/src/interactions/slashcommands/stop.ts @@ -33,7 +33,7 @@ class StopCommand extends BaseSlashCommandInteraction { } logger.debug('Responding with success embed.'); - return await interaction.editReply({ + return await interaction.reply({ embeds: [ new EmbedBuilder() .setAuthor(this.getEmbedUserAuthor(interaction)) diff --git a/src/interactions/slashcommands/systemstatus.ts b/src/interactions/slashcommands/systemstatus.ts index 7096a7b..743b134 100644 --- a/src/interactions/slashcommands/systemstatus.ts +++ b/src/interactions/slashcommands/systemstatus.ts @@ -26,6 +26,9 @@ class SystemStatusCommand extends BaseSlashCommandInteraction { await this.runValidators({ interaction, executionId }, [checkValidGuildId]); + await interaction.deferReply(); + logger.debug('Interaction deferred.'); + const [botStatisticsEmbedString, playerStatisticsEmbedString, systemStatusEmbedString] = await Promise.all([ getBotStatistics(client!, version, translator), getPlayerStatistics(client!, translator), diff --git a/src/interactions/slashcommands/volume.ts b/src/interactions/slashcommands/volume.ts index af3f612..178f858 100644 --- a/src/interactions/slashcommands/volume.ts +++ b/src/interactions/slashcommands/volume.ts @@ -31,6 +31,9 @@ class VolumeCommand extends BaseSlashCommandInteraction { checkQueueExists ]); + await interaction.deferReply(); + logger.debug('Interaction deferred.'); + const volume: number = interaction.options.getInteger('percentage')!; if (!volume && volume !== 0) { diff --git a/src/types/interactionTypes.d.ts b/src/types/interactionTypes.d.ts index 08ea632..1e74c76 100644 --- a/src/types/interactionTypes.d.ts +++ b/src/types/interactionTypes.d.ts @@ -47,11 +47,11 @@ export type BaseComponentParams = { referenceId?: string; } & BaseInteractionParams; -export type BaseSlashCommandReturnType = Promise | void>; +export type BaseSlashCommandReturnType = Promise | InteractionResponse | void>; export type BaseAutocompleteReturnType = Promise; -export type BaseComponentReturnType = Promise | void>; +export type BaseComponentReturnType = Promise | InteractionResponse | void>; export enum FilterType { FFmpeg = 'ffmpeg',