Added music commands
This commit is contained in:
56
src/commands/music.ts
Normal file
56
src/commands/music.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import { PermissionFlagsBits, SlashCommandBuilder } from "discord.js"
|
||||
import { Command } from "interfaces"
|
||||
import play from "./music/play"
|
||||
import leave from "./music/leave"
|
||||
import queue from "./music/queue"
|
||||
|
||||
export = {
|
||||
name: "music",
|
||||
description: "Subcommands for music commands",
|
||||
dev: true,
|
||||
public: false,
|
||||
subcommands: true,
|
||||
|
||||
data: new SlashCommandBuilder()
|
||||
.setName("music")
|
||||
.setDescription("Subcommands for music commands")
|
||||
.addSubcommand(subcommand =>
|
||||
subcommand
|
||||
.setName("play")
|
||||
.setDescription("Play a song")
|
||||
.addStringOption(option =>
|
||||
option
|
||||
.setName("query")
|
||||
.setDescription("The song to play")
|
||||
.setAutocomplete(true)
|
||||
.setRequired(true)))
|
||||
.addSubcommand(subcommand =>
|
||||
subcommand
|
||||
.setName("queue")
|
||||
.setDescription("Show the queue"))
|
||||
.addSubcommand(subcommand =>
|
||||
subcommand
|
||||
.setName("leave")
|
||||
.setDescription("Leave the voice channel"))
|
||||
.setDMPermission(false)
|
||||
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator),
|
||||
|
||||
async execute(interaction) {
|
||||
const subcommand = interaction.options.getSubcommand()
|
||||
|
||||
if (subcommand === "play") {
|
||||
play(interaction)
|
||||
return
|
||||
}
|
||||
|
||||
if (subcommand === "queue") {
|
||||
queue(interaction)
|
||||
return
|
||||
}
|
||||
|
||||
if (subcommand === "leave") {
|
||||
leave(interaction)
|
||||
return
|
||||
}
|
||||
}
|
||||
} as Command
|
||||
26
src/commands/music/leave.ts
Normal file
26
src/commands/music/leave.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { embedColor } from "config/options"
|
||||
import { useMainPlayer } from "discord-player"
|
||||
import { ChatInputCommandInteraction } from "discord.js"
|
||||
|
||||
export default async function leave(interaction: ChatInputCommandInteraction) {
|
||||
const player = useMainPlayer()
|
||||
const queue = player.queues.get(interaction.guildId!)
|
||||
if (!queue) {
|
||||
await interaction.reply({
|
||||
embeds: [{
|
||||
description: "There is no music playing",
|
||||
color: embedColor
|
||||
}]
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
queue.delete()
|
||||
await interaction.reply({
|
||||
embeds: [{
|
||||
description: "Left the voice channel",
|
||||
color: embedColor
|
||||
}]
|
||||
})
|
||||
}
|
||||
41
src/commands/music/play.ts
Normal file
41
src/commands/music/play.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { embedColor } from "config/options"
|
||||
import { useMainPlayer } from "discord-player"
|
||||
import { ChatInputCommandInteraction, GuildMember } from "discord.js"
|
||||
|
||||
export default async function play(interaction: ChatInputCommandInteraction) {
|
||||
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
|
||||
}
|
||||
|
||||
const { track } = await player.play(channel, query, {
|
||||
requestedBy: interaction.user,
|
||||
nodeOptions: {
|
||||
volume: 50,
|
||||
}
|
||||
})
|
||||
|
||||
await interaction.editReply({
|
||||
embeds: [{
|
||||
description: `Playing [${track.title}](${track.url})`,
|
||||
thumbnail: {
|
||||
url: track.thumbnail
|
||||
},
|
||||
color: embedColor,
|
||||
footer: {
|
||||
text: track.duration + " minutes",
|
||||
icon_url: interaction.user.avatarURL()!
|
||||
}
|
||||
}]
|
||||
})
|
||||
}
|
||||
30
src/commands/music/queue.ts
Normal file
30
src/commands/music/queue.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { embedColor } from "config/options"
|
||||
import { useMainPlayer } from "discord-player"
|
||||
import { ChatInputCommandInteraction } from "discord.js"
|
||||
|
||||
export default async function queue(interaction: ChatInputCommandInteraction) {
|
||||
await interaction.deferReply()
|
||||
const player = useMainPlayer()
|
||||
|
||||
const queue = player.queues.get(interaction.guildId!)
|
||||
|
||||
if (!queue) {
|
||||
await interaction.editReply("There is nothing playing")
|
||||
return
|
||||
}
|
||||
|
||||
const currentSong = queue.currentTrack
|
||||
|
||||
const nowPlaying = `Now playing: [${currentSong?.title}](${currentSong?.url})`
|
||||
|
||||
const tracks = queue.tracks.map((track, index) => {
|
||||
return `${index + 1}. [${track.title}](${track.url})`
|
||||
})
|
||||
|
||||
await interaction.editReply({
|
||||
embeds: [{
|
||||
description: nowPlaying + "\n\n" + tracks.join("\n"),
|
||||
color: embedColor
|
||||
}]
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user