discord-multipurpose-bot/commands/music/play.js
Ayden cb5a906850
Some checks are pending
Docker / build (push) Waiting to run
Feat/Add Music Commands (#1)
* add simple music functionality

* update workflow

* update Dockerfile

* update Dockerfile

* update Dockerfile

* update Dockerfile

* add few more music commands

* add lyrics command

* update lyrics command

* add loop, and add categories to all commands

* change discord status

* seperate distube and change startup console theme

* Update README

* UPDATE LICENSE file

* fix docker compose image, add better error handling for distube and update tagging workflow

* switch to node-alpine image for docker

* switch to node-alpine image for docker

* update ascii

* music commands imporvements, implement live lyrics, some guards and bot leaving on empty

* use ffmpeg package rather than ffmpeg-static
2025-09-21 01:26:18 +01:00

58 lines
1.8 KiB
JavaScript

const { SlashCommandBuilder, PermissionFlagsBits } = require("discord.js");
const { requireVC } = require("../../utils/musicGuards");
module.exports = {
data: new SlashCommandBuilder()
.setName("play")
.setDescription(
"Play a song or playlist (YouTube by default; Spotify supported)."
)
.addStringOption((option) =>
option
.setName("query")
.setDescription("URL or search query")
.setRequired(true)
),
category: "Music",
async execute(interaction, client) {
try {
await interaction.deferReply();
const vc = requireVC(interaction);
// Early permission check for better UX
const me = interaction.guild.members.me;
const perms = vc.permissionsFor(me);
if (
!perms?.has(PermissionFlagsBits.Connect) ||
!perms?.has(PermissionFlagsBits.Speak)
) {
throw new Error(
"❌ I don't have permission to **Connect**/**Speak** in your voice channel."
);
}
const query = interaction.options.getString("query", true).trim();
if (!query) throw new Error("❌ Give me something to play.");
// Avoid insanely long strings
if (query.length > 2000) throw new Error("❌ Query too long.");
// Play! (YouTube is default via plugin order)
await client.distube.play(vc, query, {
textChannel: interaction.channel,
member: interaction.member,
});
await interaction.followUp(`🔍 Searching **${query.slice(0, 128)}**…`);
} catch (e) {
const msg = e?.message ?? "❌ Failed to play.";
if (interaction.deferred || interaction.replied) {
await interaction.followUp({ content: msg, ephemeral: true });
} else {
await interaction.reply({ content: msg, ephemeral: true });
}
}
},
};