From 6f25c45e5fc8d44ae7c4fed335ed3bf575b83674 Mon Sep 17 00:00:00 2001 From: Ayden Jahola Date: Sat, 20 Sep 2025 00:27:35 +0100 Subject: [PATCH] add few more music commands --- commands/music/nowplaying.js | 28 ++++++++++++++++++++++++++++ commands/music/pause.js | 26 ++++++++++++++++++++++++++ commands/music/resume.js | 26 ++++++++++++++++++++++++++ commands/music/shuffle.js | 22 ++++++++++++++++++++++ commands/music/volume.js | 31 +++++++++++++++++++++++++++++++ docker-compose.yml | 7 +++++++ index.js | 12 ++++++++++++ 7 files changed, 152 insertions(+) create mode 100644 commands/music/nowplaying.js create mode 100644 commands/music/pause.js create mode 100644 commands/music/resume.js create mode 100644 commands/music/shuffle.js create mode 100644 commands/music/volume.js create mode 100644 docker-compose.yml diff --git a/commands/music/nowplaying.js b/commands/music/nowplaying.js new file mode 100644 index 0000000..8720165 --- /dev/null +++ b/commands/music/nowplaying.js @@ -0,0 +1,28 @@ +const { SlashCommandBuilder, EmbedBuilder } = require("discord.js"); + +module.exports = { + data: new SlashCommandBuilder() + .setName("nowplaying") + .setDescription("Shows information about the current song"), + async execute(interaction, client) { + const queue = client.distube.getQueue(interaction.guildId); + + if (!queue || !queue.songs.length) { + return interaction.reply("❌ There is no music playing!"); + } + + const song = queue.songs[0]; + const embed = new EmbedBuilder() + .setColor("#0099ff") + .setTitle("🎡 Now Playing") + .setDescription(`**${song.name}**`) + .addFields( + { name: "Duration", value: song.formattedDuration, inline: true }, + { name: "Requested by", value: song.user.toString(), inline: true }, + { name: "URL", value: song.url || "No URL available" } + ) + .setThumbnail(song.thumbnail || null); + + interaction.reply({ embeds: [embed] }); + }, +}; diff --git a/commands/music/pause.js b/commands/music/pause.js new file mode 100644 index 0000000..d6a1205 --- /dev/null +++ b/commands/music/pause.js @@ -0,0 +1,26 @@ +const { SlashCommandBuilder } = require("discord.js"); + +module.exports = { + data: new SlashCommandBuilder() + .setName("pause") + .setDescription("Pauses the current song"), + async execute(interaction, client) { + const queue = client.distube.getQueue(interaction.guildId); + + if (!queue) { + return interaction.reply("❌ There is no music playing!"); + } + + if (queue.paused) { + return interaction.reply("⏸️ Music is already paused!"); + } + + try { + await queue.pause(); + interaction.reply("⏸️ Paused the current song!"); + } catch (error) { + console.error(error); + interaction.reply("❌ Failed to pause the music."); + } + }, +}; diff --git a/commands/music/resume.js b/commands/music/resume.js new file mode 100644 index 0000000..812d552 --- /dev/null +++ b/commands/music/resume.js @@ -0,0 +1,26 @@ +const { SlashCommandBuilder } = require("discord.js"); + +module.exports = { + data: new SlashCommandBuilder() + .setName("resume") + .setDescription("Resumes the paused song"), + async execute(interaction, client) { + const queue = client.distube.getQueue(interaction.guildId); + + if (!queue) { + return interaction.reply("❌ There is no music playing!"); + } + + if (!queue.paused) { + return interaction.reply("▢️ Music is not paused!"); + } + + try { + await queue.resume(); + interaction.reply("▢️ Resumed the music!"); + } catch (error) { + console.error(error); + interaction.reply("❌ Failed to resume the music."); + } + }, +}; diff --git a/commands/music/shuffle.js b/commands/music/shuffle.js new file mode 100644 index 0000000..01832d8 --- /dev/null +++ b/commands/music/shuffle.js @@ -0,0 +1,22 @@ +const { SlashCommandBuilder } = require("discord.js"); + +module.exports = { + data: new SlashCommandBuilder() + .setName("shuffle") + .setDescription("Shuffles the current queue"), + async execute(interaction, client) { + const queue = client.distube.getQueue(interaction.guildId); + + if (!queue || queue.songs.length <= 2) { + return interaction.reply("❌ Not enough songs in the queue to shuffle!"); + } + + try { + await queue.shuffle(); + interaction.reply("πŸ”€ Shuffled the queue!"); + } catch (error) { + console.error(error); + interaction.reply("❌ Failed to shuffle the queue."); + } + }, +}; diff --git a/commands/music/volume.js b/commands/music/volume.js new file mode 100644 index 0000000..50e9681 --- /dev/null +++ b/commands/music/volume.js @@ -0,0 +1,31 @@ +const { SlashCommandBuilder } = require("discord.js"); + +module.exports = { + data: new SlashCommandBuilder() + .setName("volume") + .setDescription("Adjust the playback volume (1-100)") + .addIntegerOption((option) => + option + .setName("level") + .setDescription("Volume level (1-100)") + .setRequired(true) + .setMinValue(1) + .setMaxValue(100) + ), + async execute(interaction, client) { + const volume = interaction.options.getInteger("level"); + const queue = client.distube.getQueue(interaction.guildId); + + if (!queue) { + return interaction.reply("❌ There is no music playing!"); + } + + try { + await queue.setVolume(volume); + interaction.reply(`πŸ”Š Volume set to ${volume}%!`); + } catch (error) { + console.error(error); + interaction.reply("❌ Failed to adjust volume."); + } + }, +}; diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..abee2fa --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,7 @@ +--- +services: + bot: + image: ghcr.io/aydenjahola/discord-multipurpose-bot:music + container_name: discord-bot + restart: unless-stopped + env_file: .env diff --git a/index.js b/index.js index 480f1f3..cc11b35 100644 --- a/index.js +++ b/index.js @@ -52,6 +52,18 @@ client.distube }) .on("finish", (queue) => { queue.textChannel.send("🎡 Queue finished!"); + }) + .on("pause", (queue) => { + queue.textChannel.send("⏸️ Music paused!"); + }) + .on("resume", (queue) => { + queue.textChannel.send("▢️ Music resumed!"); + }) + .on("volumeChange", (queue, volume) => { + queue.textChannel.send(`πŸ”Š Volume changed to ${volume}%`); + }) + .on("noRelated", (queue) => { + queue.textChannel.send("❌ Could not find related video for autoplay!"); }); // Function to recursively read commands from subdirectories