Add play autocompletion
All checks were successful
ci/woodpecker/push/publish Pipeline was successful

This commit is contained in:
Mylloon 2023-03-11 11:36:36 +01:00
parent cdce2494c5
commit f2997dfab1
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

View file

@ -1,5 +1,6 @@
import { SlashCommandBuilder } from "@discordjs/builders"; import { SlashCommandBuilder } from "@discordjs/builders";
import { import {
AutocompleteInteraction,
ChatInputCommandInteraction, ChatInputCommandInteraction,
Client, Client,
EmbedBuilder, EmbedBuilder,
@ -35,6 +36,7 @@ export default {
.setDescription(loc_default.get(`c_${filename}_opt1_desc`) ?? "") .setDescription(loc_default.get(`c_${filename}_opt1_desc`) ?? "")
.setNameLocalizations(getLocalizations(client, `c_${filename}_opt1_name`, true)) .setNameLocalizations(getLocalizations(client, `c_${filename}_opt1_name`, true))
.setDescriptionLocalizations(getLocalizations(client, `c_${filename}_opt1_desc`)) .setDescriptionLocalizations(getLocalizations(client, `c_${filename}_opt1_desc`))
.setAutocomplete(true)
) )
); );
}, },
@ -148,4 +150,24 @@ export default {
content: `⏱️ | \`${title}\` ${loc.get("c_play5")}.`, 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,
}))
);
},
}; };