Roamingstorm
Roamingstorm
DIAdiscord.js - Imagine an app
Created by Roamingstorm on 6/29/2023 in #djs-questions
/play command not working
Can you tell the command code
5 replies
DIAdiscord.js - Imagine an app
Created by Roamingstorm on 6/29/2023 in #djs-questions
/play command not working
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");
5 replies