/play command not working

client.commands = new Map(); client.commands.set("play", async (message) => { if (message.content.startsWith("/play")) { const query = message.content.slice(6); const track = query; // Replace this with your own logic to resolve the track if (track) { const voiceChannel = message.member.voice.channel; if (voiceChannel) { try { const connection = await voiceChannel.join(); connection.play(track); message.reply(Now playing: ${track}); } catch (error) { console.error(error); message.reply("An error occurred while playing the track."); } } else { message.reply("You must be in a voice channel to play music."); } } else { message.reply("Could not find track."); } } }); THis is not showing /play command in the command list
4 Replies
d.js toolkit
d.js toolkit2y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
Roamingstorm
RoamingstormOP2y ago
const { Client, GatewayIntentBits, ActivityType } = require('discord.js'); const client = new Client({ intents: [ GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildMembers, ], }); client.on("ready", async () => { console.log(Logged in as ${client.user.tag}!); // Set the bot's status client.user.setActivity("Discord.js v14", { type: "PLAYING" }); }); client.commands = new Map(); client.commands.set("play", async (message) => { if (message.content.startsWith("/play")) { const query = message.content.slice(6); const track = query; // Replace this with your own logic to resolve the track if (track) { const voiceChannel = message.member.voice.channel; if (voiceChannel) { try { const connection = await voiceChannel.join(); connection.play(track); message.reply(Now playing: ${track}); } catch (error) { console.error(error); message.reply("An error occurred while playing the track."); } } else { message.reply("You must be in a voice channel to play music."); } } else { message.reply("Could not find track."); } } }); // To show the available commands when requested client.on("messageCreate", (message) => { if (message.content === "/commands") { const commandList = Array.from(client.commands.keys()).join(", "); message.reply(Available commands: ${commandList}); } }); client.login("YOUR_TOKEN_HERE");
d.js docs
d.js docs2y ago
guide Creating Your Bot: Creating slash commands read more
Roamingstorm
RoamingstormOP2y ago
Can you tell the command code
Want results from more Discord servers?
Add your server