Added music commands
This commit is contained in:
32
src/components/autocomplete/music.ts
Normal file
32
src/components/autocomplete/music.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
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
|
||||
Reference in New Issue
Block a user