aboutsummaryrefslogtreecommitdiff
path: root/src/commands/play.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/commands/play.ts')
-rw-r--r--src/commands/play.ts19
1 files changed, 17 insertions, 2 deletions
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,
+ })));
+ }
}