54 lines
1.4 KiB
TypeScript
54 lines
1.4 KiB
TypeScript
import { useMainPlayer } from "discord-player"
|
|
import { GuildMember } from "discord.js"
|
|
import { embedColor } from "~/config/options.js"
|
|
import { SubCommand } from "~/typings"
|
|
|
|
const cmd: SubCommand = async (interaction) => {
|
|
await interaction.deferReply()
|
|
const query = interaction.options.getString("query")!
|
|
const channel = (interaction.member as GuildMember).voice.channel
|
|
const player = useMainPlayer()
|
|
|
|
if (!channel) {
|
|
await interaction.editReply({
|
|
embeds: [{
|
|
description: "You need to be in a voice channel to play music",
|
|
color: embedColor
|
|
}]
|
|
})
|
|
return
|
|
}
|
|
|
|
let replyMessage: string = ""
|
|
const queue = player.queues.get(interaction.guildId!)
|
|
|
|
const { track } = await player.play(channel, query, {
|
|
requestedBy: interaction.user,
|
|
nodeOptions: {
|
|
volume: 25
|
|
}
|
|
})
|
|
|
|
if (queue) {
|
|
replyMessage = `Added [${track.title}](${track.url}) to the queue`
|
|
} else {
|
|
replyMessage = `Playing [${track.title}](${track.url})`
|
|
}
|
|
|
|
await interaction.editReply({
|
|
embeds: [{
|
|
description: replyMessage,
|
|
thumbnail: {
|
|
url: track.thumbnail
|
|
},
|
|
color: embedColor,
|
|
footer: {
|
|
text: track.duration + " minutes",
|
|
icon_url: interaction.user.avatarURL()!
|
|
}
|
|
}]
|
|
})
|
|
}
|
|
|
|
export default cmd
|