Files
illegitimate-bot/src/components/autocomplete/music.ts
2024-02-09 20:09:27 +01:00

32 lines
958 B
TypeScript

import { QueryType, useMainPlayer } from "discord-player"
import { Autocomplete } from "interfaces"
export = {
name: "music",
description: "Music",
async execute(interaction) {
const focusedOption = interaction.options.getFocused(true)
if (interaction.options.getSubcommand() !== "play" && focusedOption.name !== "query") return
if (focusedOption.value === "") {
await interaction.respond([{
name: "Please start typing a song to play",
value: "none"
}])
return
}
const player = useMainPlayer()
const { tracks } = await player.search(focusedOption.value, {
searchEngine: QueryType.YOUTUBE_SEARCH
})
const results = tracks.map(track => ({
name: track.title,
value: track.url
}))
await interaction.respond(results.slice(0, 25)).catch()
}
} as Autocomplete