mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-03 22:15:37 +00:00
feat: Autocomplete queries in /play command
This commit is contained in:
1 parent
7e0479c299
commit
025715c0da
2 files changed
+74
-45
No files matched your search
@@ -11,7 +11,31 @@ module.exports = {
|
||||
.setName('play')
|
||||
.setDescription('Add a track or playlist to the queue by searching or url.')
|
||||
.setDMPermission(false)
|
||||
.addStringOption((option) => option.setName('query').setDescription('Search query or URL.').setRequired(true)),
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName('query')
|
||||
.setDescription('Search query or URL.')
|
||||
.setRequired(true)
|
||||
.setMinLength(2)
|
||||
.setMaxLength(500)
|
||||
.setAutocomplete(true)
|
||||
),
|
||||
autocomplete: async ({ interaction }) => {
|
||||
const player = useMainPlayer();
|
||||
const query = interaction.options.getString('query', true);
|
||||
if (query.length < 2) {
|
||||
return;
|
||||
}
|
||||
const searchResults = await player.search(query);
|
||||
|
||||
logger.debug(`[Shard ${interaction.guild.shardId}] Autocomplete search responded for query: ${query}`);
|
||||
return interaction.respond(
|
||||
searchResults.tracks.slice(0, 5).map((track) => ({
|
||||
name: `${track.title} [Author: ${track.author}]`,
|
||||
value: track.url
|
||||
}))
|
||||
);
|
||||
},
|
||||
execute: async ({ interaction }) => {
|
||||
if (await notInVoiceChannel(interaction)) {
|
||||
return;
|
||||
|
||||
Reference in new issue
Block a user