From f2997dfab1e0af8b68f910538e848205764b4f86 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sat, 11 Mar 2023 11:36:36 +0100 Subject: [PATCH] Add play autocompletion --- src/commands/music/play.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/commands/music/play.ts b/src/commands/music/play.ts index 7821691..d2e2dc5 100644 --- a/src/commands/music/play.ts +++ b/src/commands/music/play.ts @@ -1,5 +1,6 @@ import { SlashCommandBuilder } from "@discordjs/builders"; import { + AutocompleteInteraction, ChatInputCommandInteraction, Client, EmbedBuilder, @@ -35,6 +36,7 @@ export default { .setDescription(loc_default.get(`c_${filename}_opt1_desc`) ?? "") .setNameLocalizations(getLocalizations(client, `c_${filename}_opt1_name`, true)) .setDescriptionLocalizations(getLocalizations(client, `c_${filename}_opt1_desc`)) + .setAutocomplete(true) ) ); }, @@ -148,4 +150,24 @@ export default { content: `⏱️ | \`${title}\` ${loc.get("c_play5")}.`, }); }, + + autocomplete: async (interaction: AutocompleteInteraction) => { + const loc_default = interaction.client.locales.get(interaction.client.config.default_lang); + const filename = getFilename(__filename); + + const player = useMasterPlayer() as Player; + const query = interaction.options.getString( + loc_default?.get(`c_${filename}_opt1_name`) as string, + true + ); + const results = await player.search(query); + + // Returns a list of songs with their title + return interaction.respond( + results.tracks.slice(0, 10).map((t) => ({ + name: t.title, + value: t.url, + })) + ); + }, };