diff --git a/src/interactions/commands/player/filters.ts b/src/interactions/commands/player/filters.ts index 2d88a2e..571417c 100644 --- a/src/interactions/commands/player/filters.ts +++ b/src/interactions/commands/player/filters.ts @@ -10,6 +10,7 @@ import { ChatInputCommandInteraction, ComponentType, EmbedBuilder, + Message, SlashCommandBuilder, StringSelectMenuBuilder, StringSelectMenuOptionBuilder @@ -78,7 +79,7 @@ class FiltersCommand extends BaseSlashCommandInteraction { logger: Logger, interaction: ChatInputCommandInteraction, queue: GuildQueue - ) { + ): Promise { const filterOptions: StringSelectMenuOptionBuilder[] = []; ffmpegFilterOptions.availableFilters.forEach((filter: FFmpegFilterOption) => { @@ -136,7 +137,11 @@ class FiltersCommand extends BaseSlashCommandInteraction { }); } - private async tempDisableFilters(logger: Logger, interaction: ChatInputCommandInteraction, queue: GuildQueue) { + private async tempDisableFilters( + logger: Logger, + interaction: ChatInputCommandInteraction, + queue: GuildQueue + ): Promise { if (queue.filters.ffmpeg.filters.length > 0) { queue.filters.ffmpeg.setFilters(false); logger.debug('Reset queue filters.'); @@ -157,7 +162,10 @@ class FiltersCommand extends BaseSlashCommandInteraction { }); } - private async tempNotImplementedResponse(logger: Logger, interaction: ChatInputCommandInteraction) { + private async tempNotImplementedResponse( + logger: Logger, + interaction: ChatInputCommandInteraction + ): Promise { logger.debug('Responding with info embed.'); return await interaction.editReply({ embeds: [ diff --git a/src/interactions/commands/player/lyrics.ts b/src/interactions/commands/player/lyrics.ts index bc54fe6..dc5ffc1 100644 --- a/src/interactions/commands/player/lyrics.ts +++ b/src/interactions/commands/player/lyrics.ts @@ -1,6 +1,6 @@ import { LyricsData, lyricsExtractor } from '@discord-player/extractor'; import { GuildQueue, Player, QueryType, SearchResult, Track, useMainPlayer, useQueue } from 'discord-player'; -import { ChatInputCommandInteraction, EmbedBuilder, SlashCommandBuilder } from 'discord.js'; +import { ChatInputCommandInteraction, EmbedBuilder, Message, SlashCommandBuilder } from 'discord.js'; import { Logger } from 'pino'; import { BaseSlashCommandInteraction } from '../../../classes/interactions'; import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes'; @@ -178,7 +178,7 @@ class LyricsCommand extends BaseSlashCommandInteraction { logger: Logger, interaction: ChatInputCommandInteraction, geniusLyricsResult: LyricsData - ) { + ): Promise { logger.debug('Lyrics text too long, splitting into multiple messages.'); const messageCount: number = Math.ceil(geniusLyricsResult.lyrics.length / 3800); const embedList: EmbedBuilder[] = []; @@ -200,7 +200,7 @@ class LyricsCommand extends BaseSlashCommandInteraction { } logger.debug('Responding with multiple info embeds.'); - await interaction.editReply({ + return await interaction.editReply({ embeds: embedList }); } @@ -209,7 +209,7 @@ class LyricsCommand extends BaseSlashCommandInteraction { logger: Logger, interaction: ChatInputCommandInteraction, geniusLyricsResult: LyricsData - ) { + ): Promise { logger.debug('Responding with info embed.'); return await interaction.editReply({ embeds: [ diff --git a/src/interactions/commands/player/play.ts b/src/interactions/commands/player/play.ts index 0ff3b1c..428d3e3 100644 --- a/src/interactions/commands/player/play.ts +++ b/src/interactions/commands/player/play.ts @@ -1,5 +1,5 @@ import { GuildQueue, Player, SearchResult, Track, useMainPlayer, useQueue } from 'discord-player'; -import { ChatInputCommandInteraction, EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js'; +import { ChatInputCommandInteraction, EmbedBuilder, GuildMember, Message, SlashCommandBuilder } from 'discord.js'; import { Logger } from 'pino'; import { BaseSlashCommandInteraction, CustomError } from '../../../classes/interactions'; import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes'; @@ -75,9 +75,9 @@ class PlayCommand extends BaseSlashCommandInteraction { transformedQuery: string, interaction: ChatInputCommandInteraction, logger: Logger - ) { + ): Promise { logger.debug(`Searching for track with query: '${transformedQuery}'.`); - let searchResult; + let searchResult: SearchResult | undefined; try { searchResult = await player.search(transformedQuery, { requestedBy: interaction.user @@ -95,7 +95,7 @@ class PlayCommand extends BaseSlashCommandInteraction { logger: Logger, executionId: string, query: string - ) { + ): Promise { let track; try { logger.debug(`Attempting to add track with player.play(). Query: '${query}'.`); @@ -116,11 +116,11 @@ class PlayCommand extends BaseSlashCommandInteraction { } catch (error) { if (error instanceof CustomError) { if (error.message.includes('Sign in to confirm your age')) { - return this.handleAgeConfirmationError(interaction, logger, executionId); + this.handleAgeConfirmationError(interaction, logger, executionId); } if (error.message.includes('The following content may contain')) { - return this.handleSensitiveTopicError(interaction, logger, executionId); + this.handleSensitiveTopicError(interaction, logger, executionId); } if ( @@ -128,17 +128,19 @@ class PlayCommand extends BaseSlashCommandInteraction { error.message.includes('Failed to fetch resources for ytdl streaming') || error.message.includes('Could not extract stream for this track') ) { - return this.handleStreamError(interaction, logger, executionId, error, query); + this.handleStreamError(interaction, logger, executionId, error, query); } if (error.message === 'Cancelled') { - return this.handleCancelledError(interaction, logger, executionId, query); + this.handleCancelledError(interaction, logger, executionId, query); } logger.error(error, 'Failed to play track with player.play(), unhandled error.'); } else { throw error; } + + return Promise.resolve(); } return track; } @@ -148,7 +150,7 @@ class PlayCommand extends BaseSlashCommandInteraction { searchResult: SearchResult, interaction: ChatInputCommandInteraction, logger: Logger - ) { + ): Promise { logger.debug('Result found and added with player.play(), added to queue.'); const queue: GuildQueue = useQueue(interaction.guild!.id)!; const trackUrl = this.getDisplayTrackDurationAndUrl(track); @@ -177,7 +179,7 @@ class PlayCommand extends BaseSlashCommandInteraction { transformedQuery: string, interaction: ChatInputCommandInteraction, logger: Logger - ) { + ): Promise { logger.debug(`No results found for query: '${transformedQuery}'`); logger.debug('Responding with warning embed.'); @@ -194,7 +196,11 @@ class PlayCommand extends BaseSlashCommandInteraction { }); } - private async handlePlaylistTooLarge(query: string, interaction: ChatInputCommandInteraction, logger: Logger) { + private async handlePlaylistTooLarge( + query: string, + interaction: ChatInputCommandInteraction, + logger: Logger + ): Promise { logger.debug(`Playlist found but would exceed max queue size. Query: '${query}'.`); logger.debug('Responding with warning embed.'); @@ -215,11 +221,11 @@ class PlayCommand extends BaseSlashCommandInteraction { interaction: ChatInputCommandInteraction, logger: Logger, executionId: string - ) { + ): Promise { logger.debug('Found track but failed to retrieve audio due to age confirmation warning.'); logger.debug('Responding with warning embed.'); - await interaction.editReply({ + return await interaction.editReply({ embeds: [ new EmbedBuilder() .setDescription( @@ -231,18 +237,17 @@ class PlayCommand extends BaseSlashCommandInteraction { .setFooter({ text: `Execution ID: ${executionId}` }) ] }); - return Promise.resolve(); } private async handleSensitiveTopicError( interaction: ChatInputCommandInteraction, logger: Logger, executionId: string - ) { + ): Promise { logger.debug('Found track but failed to retrieve audio due to graphic/mature/sensitive topic warning.'); logger.debug('Responding with warning embed.'); - await interaction.editReply({ + return await interaction.editReply({ embeds: [ new EmbedBuilder() .setDescription( @@ -254,7 +259,6 @@ class PlayCommand extends BaseSlashCommandInteraction { .setFooter({ text: `Execution ID: ${executionId}` }) ] }); - return Promise.resolve(); } private async handleStreamError( @@ -263,11 +267,11 @@ class PlayCommand extends BaseSlashCommandInteraction { executionId: string, error: Error, query: string - ) { + ): Promise { logger.debug(error, `Found track but failed to retrieve audio. Query: ${query}.`); logger.debug('Responding with error embed.'); - await interaction.editReply({ + return await interaction.editReply({ embeds: [ new EmbedBuilder() .setDescription( @@ -280,7 +284,6 @@ class PlayCommand extends BaseSlashCommandInteraction { .setFooter({ text: `Execution ID: ${executionId}` }) ] }); - return Promise.resolve(); } private async handleCancelledError( @@ -288,11 +291,11 @@ class PlayCommand extends BaseSlashCommandInteraction { logger: Logger, executionId: string, query: string - ) { + ): Promise { logger.debug(`Operation cancelled. Query: ${query}.`); logger.debug('Responding with error embed.'); - await interaction.editReply({ + return await interaction.editReply({ embeds: [ new EmbedBuilder() .setDescription( @@ -305,7 +308,6 @@ class PlayCommand extends BaseSlashCommandInteraction { .setFooter({ text: `Execution ID: ${executionId}` }) ] }); - return Promise.resolve(); } } diff --git a/src/utils/registerClientInteractions.ts b/src/utils/registerClientInteractions.ts index 4c9fac3..e8df56f 100644 --- a/src/utils/registerClientInteractions.ts +++ b/src/utils/registerClientInteractions.ts @@ -21,7 +21,7 @@ export const registerClientInteractions = async ({ client, executionId }: Regist logger.debug('Registering all client interactions complete.'); }; -async function registerSlashCommandInteractions(logger: Logger, client: ExtendedClient) { +async function registerSlashCommandInteractions(logger: Logger, client: ExtendedClient): Promise { logger.debug('Registering client slash command interactions...'); client.slashCommandInteractions = new Collection(); @@ -61,7 +61,7 @@ async function registerSlashCommandInteractions(logger: Logger, client: Extended logger.trace('Registering client slash command interactions complete.'); } -async function registerAutocompleteInteractions(logger: Logger, client: ExtendedClient) { +async function registerAutocompleteInteractions(logger: Logger, client: ExtendedClient): Promise { logger.debug('Registering client autocomplete interactions...'); client.autocompleteInteractions = new Collection(); @@ -91,7 +91,7 @@ async function registerAutocompleteInteractions(logger: Logger, client: Extended logger.trace('Registering client autocomplete interactions complete.'); } -async function registerComponentInteractions(logger: Logger, client: ExtendedClient) { +async function registerComponentInteractions(logger: Logger, client: ExtendedClient): Promise { logger.debug('Registering client component interactions...'); client.componentInteractions = new Collection();