aboutsummaryrefslogtreecommitdiff
path: root/src/commands
diff options
context:
space:
mode:
authorMax Isom <[email protected]>2022-01-19 18:15:12 -0600
committerMax Isom <[email protected]>2022-01-19 18:15:12 -0600
commit7901fcce3d7d0ce2ec91ba36a3ba9107e8709bff (patch)
tree3587d2d2e6c2f7a49118229453cf42f1b0629226 /src/commands
parent43baa57c51ce25aadf7b9d5a75a992e6c1edc7da (diff)
downloadmuse-7901fcce3d7d0ce2ec91ba36a3ba9107e8709bff.tar.xz
muse-7901fcce3d7d0ce2ec91ba36a3ba9107e8709bff.zip
✨ add autocomplete
Diffstat (limited to 'src/commands')
-rw-r--r--src/commands/index.ts3
-rw-r--r--src/commands/play.ts19
2 files changed, 19 insertions, 3 deletions
diff --git a/src/commands/index.ts b/src/commands/index.ts
index b9f5877..1d1646f 100644
--- a/src/commands/index.ts
+++ b/src/commands/index.ts
@@ -1,5 +1,5 @@
import {SlashCommandBuilder} from '@discordjs/builders';
-import {ButtonInteraction, CommandInteraction} from 'discord.js';
+import {AutocompleteInteraction, ButtonInteraction, CommandInteraction} from 'discord.js';
export default interface Command {
readonly slashCommand: Partial<SlashCommandBuilder> & Pick<SlashCommandBuilder, 'toJSON'>;
@@ -7,4 +7,5 @@ export default interface Command {
readonly requiresVC?: boolean;
execute: (interaction: CommandInteraction) => Promise<void>;
handleButtonInteraction?: (interaction: ButtonInteraction) => Promise<void>;
+ handleAutocompleteInteraction?: (interaction: AutocompleteInteraction) => Promise<void>;
}
diff --git a/src/commands/play.ts b/src/commands/play.ts
index 619c18f..7e5dee1 100644
--- a/src/commands/play.ts
+++ b/src/commands/play.ts
@@ -1,4 +1,4 @@
-import {CommandInteraction, GuildMember} from 'discord.js';
+import {AutocompleteInteraction, CommandInteraction, GuildMember} from 'discord.js';
import {URL} from 'url';
import {Except} from 'type-fest';
import {SlashCommandBuilder} from '@discordjs/builders';
@@ -12,6 +12,7 @@ import {getMostPopularVoiceChannel, getMemberVoiceChannel} from '../utils/channe
import errorMsg from '../utils/error-msg.js';
import GetSongs from '../services/get-songs.js';
import {prisma} from '../utils/db.js';
+import getYouTubeSuggestionsFor from '../utils/get-youtube-suggestions-for.js';
@injectable()
export default class implements Command {
@@ -21,7 +22,8 @@ export default class implements Command {
.setDescription('play a song or resume playback')
.addStringOption(option => option
.setName('query')
- .setDescription('YouTube URL, Spotify URL, or search query'))
+ .setDescription('YouTube URL, Spotify URL, or search query')
+ .setAutocomplete(true))
.addBooleanOption(option => option
.setName('immediate')
.setDescription('adds track to the front of the queue'))
@@ -191,4 +193,17 @@ export default class implements Command {
await interaction.editReply(`u betcha, **${firstSong.title}** and ${newSongs.length - 1} other songs were added to the queue${extraMsg}`);
}
}
+
+ public async handleAutocompleteInteraction(interaction: AutocompleteInteraction): Promise<void> {
+ const query = interaction.options.getString('query')?.trim();
+
+ if (!query || query.length === 0) {
+ return interaction.respond([]);
+ }
+
+ await interaction.respond((await getYouTubeSuggestionsFor(query)).map(s => ({
+ name: s,
+ value: s,
+ })));
+ }
}