Updated music commands

This commit is contained in:
2024-02-10 16:03:46 +01:00
parent cbeeeca8d8
commit 23a7db55e1
8 changed files with 137 additions and 12 deletions

View File

@@ -6,6 +6,8 @@ import queue from "./music/queue"
import volume from "./music/volume" import volume from "./music/volume"
import skip from "./music/skip" import skip from "./music/skip"
import nowplaying from "./music/nowplaying" import nowplaying from "./music/nowplaying"
import pause from "./music/pause"
import unpause from "./music/unpause"
export = { export = {
name: "music", name: "music",
@@ -54,6 +56,14 @@ export = {
subcommand subcommand
.setName("nowplaying") .setName("nowplaying")
.setDescription("Show the currently playing song")) .setDescription("Show the currently playing song"))
.addSubcommand(subcommand =>
subcommand
.setName("pause")
.setDescription("Pause the music"))
.addSubcommand(subcommand =>
subcommand
.setName("unpause")
.setDescription("Unpause the music"))
.addSubcommand(subcommand => .addSubcommand(subcommand =>
subcommand subcommand
.setName("leave") .setName("leave")
@@ -89,6 +99,16 @@ export = {
return return
} }
if (subcommand === "pause") {
pause(interaction)
return
}
if (subcommand === "unpause") {
unpause(interaction)
return
}
if (subcommand === "leave") { if (subcommand === "leave") {
leave(interaction) leave(interaction)
return return

View File

@@ -10,25 +10,27 @@ export default async function nowplaying(interaction: ChatInputCommandInteractio
if (!queue) { if (!queue) {
await interaction.editReply({ await interaction.editReply({
content: "There is no queue" embeds: [{
description: "There is no music playing",
color: embedColor
}]
}) })
return return
} }
const current = queue.currentTrack const current = queue.currentTrack
if (!current) { if (!current) {
await interaction.editReply({ await interaction.editReply({
content: "There is no current song" embeds: [{
description: "There is no music playing",
color: embedColor
}]
}) })
return return
} }
await interaction.editReply({ await interaction.editReply({
embeds: [{ embeds: [{
author: {
name: current.author,
},
title: "Now Playing", title: "Now Playing",
description: `[${current.title}](${current.url})`, description: `[${current.title}](${current.url})`,
color: embedColor, color: embedColor,

View File

@@ -0,0 +1,38 @@
import { embedColor } from "config/options"
import { useMainPlayer } from "discord-player"
import { ChatInputCommandInteraction } from "discord.js"
export default async function pause(interaction: ChatInputCommandInteraction) {
await interaction.deferReply()
const player = useMainPlayer()
const queue = player.queues.get(interaction.guildId!)
if (!queue) {
await interaction.editReply({
embeds: [{
description: "There is no music playing",
color: embedColor
}]
})
return
}
if (queue.node.isPaused()) {
await interaction.editReply({
embeds: [{
description: "The music is already paused",
color: embedColor
}]
})
return
}
queue.node.setPaused(true)
await interaction.editReply({
embeds: [{
description: "Paused the music",
color: embedColor
}]
})
}

View File

@@ -18,6 +18,8 @@ export default async function play(interaction: ChatInputCommandInteraction) {
return return
} }
// const bitRate = channel.bitrate / 1000
const { track } = await player.play(channel, query, { const { track } = await player.play(channel, query, {
requestedBy: interaction.user, requestedBy: interaction.user,
nodeOptions: { nodeOptions: {

View File

@@ -8,7 +8,12 @@ export default async function queue(interaction: ChatInputCommandInteraction) {
const queue = player.queues.get(interaction.guildId!) const queue = player.queues.get(interaction.guildId!)
if (!queue) { if (!queue) {
await interaction.editReply("There is nothing playing") await interaction.editReply({
embeds: [{
description: "There is no queue",
color: embedColor
}]
})
return return
} }
@@ -20,8 +25,15 @@ export default async function queue(interaction: ChatInputCommandInteraction) {
await interaction.editReply({ await interaction.editReply({
embeds: [{ embeds: [{
title: "Queue",
description: nowPlaying + "\n\n" + tracks.join("\n"), description: nowPlaying + "\n\n" + tracks.join("\n"),
color: embedColor thumbnail: {
url: currentSong?.thumbnail || ""
},
color: embedColor,
footer: {
text: `Total tracks: ${queue.tracks.size}`
}
}] }]
}) })
} }

View File

@@ -1,3 +1,4 @@
import { embedColor } from "config/options"
import { useMainPlayer } from "discord-player" import { useMainPlayer } from "discord-player"
import { ChatInputCommandInteraction } from "discord.js" import { ChatInputCommandInteraction } from "discord.js"
@@ -10,14 +11,20 @@ export default async function skip(interaction: ChatInputCommandInteraction) {
if (!queue) { if (!queue) {
await interaction.editReply({ await interaction.editReply({
content: "There is no queue" embeds: [{
description: "There is no queue",
color: embedColor
}]
}) })
return return
} }
if (amount > queue.size) { if (amount > queue.size) {
await interaction.editReply({ await interaction.editReply({
content: `There are only ${queue.size} songs in the queue` embeds: [{
description: `There are only ${queue.size} song${queue.size === 1 ? "" : "s"} in the queue`,
color: embedColor
}]
}) })
return return
} }
@@ -29,6 +36,9 @@ export default async function skip(interaction: ChatInputCommandInteraction) {
} }
await interaction.editReply({ await interaction.editReply({
content: `Skipped ${amount} song${amount === 1 ? "" : "s"}` embeds: [{
description: `Skipped ${amount === 1 ? "1 song" : `${amount} songs`}`,
color: embedColor
}]
}) })
} }

View File

@@ -0,0 +1,38 @@
import { embedColor } from "config/options"
import { useMainPlayer } from "discord-player"
import { ChatInputCommandInteraction } from "discord.js"
export default async function pause(interaction: ChatInputCommandInteraction) {
await interaction.deferReply()
const player = useMainPlayer()
const queue = player.queues.get(interaction.guildId!)
if (!queue) {
await interaction.editReply({
embeds: [{
description: "There is no music playing",
color: embedColor
}]
})
return
}
if (!queue.node.isPaused()) {
await interaction.editReply({
embeds: [{
description: "The music is not paused",
color: embedColor
}]
})
return
}
queue.node.setPaused(false)
await interaction.editReply({
embeds: [{
description: "Unpaused the music",
color: embedColor
}]
})
}

View File

@@ -11,7 +11,10 @@ export default async function volume(interaction: ChatInputCommandInteraction) {
if (!queue) { if (!queue) {
await interaction.editReply({ await interaction.editReply({
content: "There is no queue" embeds: [{
description: "There is no music playing",
color: embedColor
}]
}) })
return return
} }