From 8f16c65bb8a299a0564cc05df65e48ef90b41dac Mon Sep 17 00:00:00 2001 From: Taken Date: Sat, 10 Feb 2024 12:18:40 +0100 Subject: [PATCH] Updated music commands --- src/commands/music.ts | 31 +++++++++++++++++++++++++ src/commands/music/leave.ts | 1 - src/commands/music/play.ts | 2 +- src/commands/music/queue.ts | 3 --- src/commands/music/skip.ts | 34 ++++++++++++++++++++++++++++ src/commands/music/volume.ts | 26 +++++++++++++++++++++ src/components/autocomplete/music.ts | 2 +- 7 files changed, 93 insertions(+), 6 deletions(-) create mode 100644 src/commands/music/skip.ts create mode 100644 src/commands/music/volume.ts diff --git a/src/commands/music.ts b/src/commands/music.ts index 96cbed1..90117aa 100644 --- a/src/commands/music.ts +++ b/src/commands/music.ts @@ -3,6 +3,8 @@ import { Command } from "interfaces" import play from "./music/play" import leave from "./music/leave" import queue from "./music/queue" +import volume from "./music/volume" +import skip from "./music/skip" export = { name: "music", @@ -24,6 +26,25 @@ export = { .setDescription("The song to play") .setAutocomplete(true) .setRequired(true))) + .addSubcommand(subcommand => + subcommand + .setName("volume") + .setDescription("Change the volume of the music") + .addNumberOption(option => + option + .setName("volume") + .setDescription("The volume to set") + .setMinValue(1) + .setMaxValue(100) + .setRequired(true))) + .addSubcommand(subcommand => + subcommand + .setName("skip") + .setDescription("Skip the current song") + .addNumberOption(option => + option + .setName("amount") + .setDescription("The amount of songs to skip"))) .addSubcommand(subcommand => subcommand .setName("queue") @@ -43,6 +64,16 @@ export = { return } + if (subcommand === "volume") { + volume(interaction) + return + } + + if (subcommand === "skip") { + skip(interaction) + return + } + if (subcommand === "queue") { queue(interaction) return diff --git a/src/commands/music/leave.ts b/src/commands/music/leave.ts index e6c61eb..c223de2 100644 --- a/src/commands/music/leave.ts +++ b/src/commands/music/leave.ts @@ -15,7 +15,6 @@ export default async function leave(interaction: ChatInputCommandInteraction) { return } - queue.delete() await interaction.reply({ embeds: [{ diff --git a/src/commands/music/play.ts b/src/commands/music/play.ts index f7c24f6..ceee052 100644 --- a/src/commands/music/play.ts +++ b/src/commands/music/play.ts @@ -21,7 +21,7 @@ export default async function play(interaction: ChatInputCommandInteraction) { const { track } = await player.play(channel, query, { requestedBy: interaction.user, nodeOptions: { - volume: 50, + volume: 25, } }) diff --git a/src/commands/music/queue.ts b/src/commands/music/queue.ts index d9e1fd7..5c81407 100644 --- a/src/commands/music/queue.ts +++ b/src/commands/music/queue.ts @@ -5,7 +5,6 @@ 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) { @@ -14,9 +13,7 @@ export default async function queue(interaction: ChatInputCommandInteraction) { } 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})` }) diff --git a/src/commands/music/skip.ts b/src/commands/music/skip.ts new file mode 100644 index 0000000..5dfac5c --- /dev/null +++ b/src/commands/music/skip.ts @@ -0,0 +1,34 @@ +import { useMainPlayer } from "discord-player" +import { ChatInputCommandInteraction } from "discord.js" + +export default async function skip(interaction: ChatInputCommandInteraction) { + await interaction.deferReply() + + const amount = interaction.options.getNumber("amount") ?? 1 + const player = useMainPlayer() + const queue = player.queues.get(interaction.guildId!) + + if (!queue) { + await interaction.editReply({ + content: "There is no queue" + }) + return + } + + if (amount > queue.size) { + await interaction.editReply({ + content: `There are only ${queue.size} songs in the queue` + }) + return + } + + if (amount === 1) { + queue.node.skip() + } else { + queue.node.skipTo(amount) + } + + await interaction.editReply({ + content: `Skipped ${amount} song${amount === 1 ? "" : "s"}` + }) +} \ No newline at end of file diff --git a/src/commands/music/volume.ts b/src/commands/music/volume.ts new file mode 100644 index 0000000..78fe8a6 --- /dev/null +++ b/src/commands/music/volume.ts @@ -0,0 +1,26 @@ +import { embedColor } from "config/options" +import { useMainPlayer } from "discord-player" +import { ChatInputCommandInteraction } from "discord.js" + +export default async function volume(interaction: ChatInputCommandInteraction) { + await interaction.deferReply() + + const volume = interaction.options.getNumber("volume")! + const player = useMainPlayer() + const queue = player.queues.get(interaction.guildId!) + + if (!queue) { + await interaction.editReply({ + content: "There is no queue" + }) + return + } + + queue.node.setVolume(volume) + await interaction.editReply({ + embeds: [{ + description: `Volume set to ${volume}`, + color: embedColor + }] + }) +} \ No newline at end of file diff --git a/src/components/autocomplete/music.ts b/src/components/autocomplete/music.ts index 241b135..bbdd851 100644 --- a/src/components/autocomplete/music.ts +++ b/src/components/autocomplete/music.ts @@ -23,7 +23,7 @@ export = { }) const results = tracks.map(track => ({ - name: track.title, + name: track.title.slice(0, 100), value: track.url }))