diff --git a/src/commands/music.ts b/src/commands/music.ts index 02d3565..e4b4ef8 100644 --- a/src/commands/music.ts +++ b/src/commands/music.ts @@ -6,6 +6,8 @@ import queue from "./music/queue" import volume from "./music/volume" import skip from "./music/skip" import nowplaying from "./music/nowplaying" +import pause from "./music/pause" +import unpause from "./music/unpause" export = { name: "music", @@ -54,6 +56,14 @@ export = { subcommand .setName("nowplaying") .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 => subcommand .setName("leave") @@ -89,6 +99,16 @@ export = { return } + if (subcommand === "pause") { + pause(interaction) + return + } + + if (subcommand === "unpause") { + unpause(interaction) + return + } + if (subcommand === "leave") { leave(interaction) return diff --git a/src/commands/music/nowplaying.ts b/src/commands/music/nowplaying.ts index 5308772..4f0f255 100644 --- a/src/commands/music/nowplaying.ts +++ b/src/commands/music/nowplaying.ts @@ -10,25 +10,27 @@ export default async function nowplaying(interaction: ChatInputCommandInteractio if (!queue) { await interaction.editReply({ - content: "There is no queue" + embeds: [{ + description: "There is no music playing", + color: embedColor + }] }) return } const current = queue.currentTrack - if (!current) { await interaction.editReply({ - content: "There is no current song" + embeds: [{ + description: "There is no music playing", + color: embedColor + }] }) return } await interaction.editReply({ embeds: [{ - author: { - name: current.author, - }, title: "Now Playing", description: `[${current.title}](${current.url})`, color: embedColor, diff --git a/src/commands/music/pause.ts b/src/commands/music/pause.ts new file mode 100644 index 0000000..dc8c201 --- /dev/null +++ b/src/commands/music/pause.ts @@ -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 + }] + }) +} \ No newline at end of file diff --git a/src/commands/music/play.ts b/src/commands/music/play.ts index ceee052..c913eb5 100644 --- a/src/commands/music/play.ts +++ b/src/commands/music/play.ts @@ -18,6 +18,8 @@ export default async function play(interaction: ChatInputCommandInteraction) { return } + // const bitRate = channel.bitrate / 1000 + const { track } = await player.play(channel, query, { requestedBy: interaction.user, nodeOptions: { diff --git a/src/commands/music/queue.ts b/src/commands/music/queue.ts index 5c81407..ea1e96b 100644 --- a/src/commands/music/queue.ts +++ b/src/commands/music/queue.ts @@ -8,7 +8,12 @@ export default async function queue(interaction: ChatInputCommandInteraction) { const queue = player.queues.get(interaction.guildId!) if (!queue) { - await interaction.editReply("There is nothing playing") + await interaction.editReply({ + embeds: [{ + description: "There is no queue", + color: embedColor + }] + }) return } @@ -20,8 +25,15 @@ export default async function queue(interaction: ChatInputCommandInteraction) { await interaction.editReply({ embeds: [{ + title: "Queue", description: nowPlaying + "\n\n" + tracks.join("\n"), - color: embedColor + thumbnail: { + url: currentSong?.thumbnail || "" + }, + color: embedColor, + footer: { + text: `Total tracks: ${queue.tracks.size}` + } }] }) } \ No newline at end of file diff --git a/src/commands/music/skip.ts b/src/commands/music/skip.ts index 5dfac5c..952225b 100644 --- a/src/commands/music/skip.ts +++ b/src/commands/music/skip.ts @@ -1,3 +1,4 @@ +import { embedColor } from "config/options" import { useMainPlayer } from "discord-player" import { ChatInputCommandInteraction } from "discord.js" @@ -10,14 +11,20 @@ export default async function skip(interaction: ChatInputCommandInteraction) { if (!queue) { await interaction.editReply({ - content: "There is no queue" + embeds: [{ + description: "There is no queue", + color: embedColor + }] }) return } if (amount > queue.size) { 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 } @@ -29,6 +36,9 @@ export default async function skip(interaction: ChatInputCommandInteraction) { } await interaction.editReply({ - content: `Skipped ${amount} song${amount === 1 ? "" : "s"}` + embeds: [{ + description: `Skipped ${amount === 1 ? "1 song" : `${amount} songs`}`, + color: embedColor + }] }) } \ No newline at end of file diff --git a/src/commands/music/unpause.ts b/src/commands/music/unpause.ts new file mode 100644 index 0000000..bf83909 --- /dev/null +++ b/src/commands/music/unpause.ts @@ -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 + }] + }) +} \ No newline at end of file diff --git a/src/commands/music/volume.ts b/src/commands/music/volume.ts index 78fe8a6..2e32c74 100644 --- a/src/commands/music/volume.ts +++ b/src/commands/music/volume.ts @@ -11,7 +11,10 @@ export default async function volume(interaction: ChatInputCommandInteraction) { if (!queue) { await interaction.editReply({ - content: "There is no queue" + embeds: [{ + description: "There is no music playing", + color: embedColor + }] }) return }