Describe the bug
An issue with running play cmd
To Reproduce
Steps to reproduce the behavior:
- Go to my discord and try bot when i try to play i get error
- See error
Expected behavior
A music bot
Desktop (please complete the following information):
Additional context
My errors i tried 2 times:
Ready! (node:25868) UnhandledPromiseRejectionWarning: Error: No video id found: play at Object.exports.getURLVideoID (C:\Users\Owner\Desktop\my-bot\node_modules\ytdl-core\lib\util.js:274:11) at Object.exports.getVideoID (C:\Users\Owner\Desktop\my-bot\node_modules\ytdl-core\lib\util.js:298:20) at Function.exports.<computed> [as getInfo] (C:\Users\Owner\Desktop\my-bot\node_modules\ytdl-core\lib\info.js:309:19) at executemusic (C:\Users\Owner\Desktop\my-bot\index.js:142:31) at Client.<anonymous> (C:\Users\Owner\Desktop\my-bot\index.js:114:5) at Client.emit (events.js:323:22) at MessageCreateAction.handle (C:\Users\Owner\Desktop\my-bot\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14) at Object.module.exports [as MESSAGE_CREATE] (C:\Users\Owner\Desktop\my-bot\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32) at WebSocketManager.handlePacket (C:\Users\Owner\Desktop\my-bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:386:31) at WebSocketShard.onPacket (C:\Users\Owner\Desktop\my-bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:436:22) (node:25868) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag
--unhandled-rejections=strict(see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2) (node:25868) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. (node:25868) UnhandledPromiseRejectionWarning: Error: No video id found: play at Object.exports.getURLVideoID (C:\Users\Owner\Desktop\my-bot\node_modules\ytdl-core\lib\util.js:274:11) at Object.exports.getVideoID (C:\Users\Owner\Desktop\my-bot\node_modules\ytdl-core\lib\util.js:298:20) at Function.exports.<computed> [as getInfo] (C:\Users\Owner\Desktop\my-bot\node_modules\ytdl-core\lib\info.js:309:19) at executemusic (C:\Users\Owner\Desktop\my-bot\index.js:142:31) at Client.<anonymous> (C:\Users\Owner\Desktop\my-bot\index.js:114:5) at Client.emit (events.js:323:22) at MessageCreateAction.handle (C:\Users\Owner\Desktop\my-bot\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14) at Object.module.exports [as MESSAGE_CREATE] (C:\Users\Owner\Desktop\my-bot\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32) at WebSocketManager.handlePacket (C:\Users\Owner\Desktop\my-bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:386:31) at WebSocketShard.onPacket (C:\Users\Owner\Desktop\my-bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:436:22) (node:25868) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag
--unhandled-rejections=strict(see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 4) (node:25868) UnhandledPromiseRejectionWarning: Error: No video id found: play at Object.exports.getURLVideoID (C:\Users\Owner\Desktop\my-bot\node_modules\ytdl-core\lib\util.js:274:11) at Object.exports.getVideoID (C:\Users\Owner\Desktop\my-bot\node_modules\ytdl-core\lib\util.js:298:20) at Function.exports.<computed> [as getInfo] (C:\Users\Owner\Desktop\my-bot\node_modules\ytdl-core\lib\info.js:309:19) at executemusic (C:\Users\Owner\Desktop\my-bot\index.js:142:31) at Client.<anonymous> (C:\Users\Owner\Desktop\my-bot\index.js:114:5) at Client.emit (events.js:323:22) at MessageCreateAction.handle (C:\Users\Owner\Desktop\my-bot\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14) at Object.module.exports [as MESSAGE_CREATE] (C:\Users\Owner\Desktop\my-bot\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32) at WebSocketManager.handlePacket (C:\Users\Owner\Desktop\my-bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:386:31) at WebSocketShard.onPacket (C:\Users\Owner\Desktop\my-bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:436:22) (node:25868) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag
--unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 6)
code:
const Discord = require('discord.js'); const { prefix, token, } = require('./config.json'); const ytdl = require('ytdl-core'); const { Client, MessageAttachment } = require('discord.js'); const client = new Client();
at top and
`const queue = new Map();
client.once("ready", () => {
console.log("Ready!");
});
client.once("reconnecting", () => {
console.log("Reconnecting!");
});
client.once("disconnect", () => {
console.log("Disconnect!");
});
client.on("message", async message => {
if (message.author.bot) return;
if (!message.content.startsWith(prefix)) return;
const serverQueue = queue.get(message.guild.id);
if (message.content.startsWith(${prefix}play
)) {
executemusic(message, serverQueue);
return;
} else if (message.content.startsWith(${prefix}skip
)) {
skip(message, serverQueue);
return;
} else if (message.content.startsWith(${prefix}stop
)) {
stop(message, serverQueue);
return;
} else {
message.channel.send("You need to enter a valid command!");
}
});
async function executemusic(message, serverQueue) {
const args = message.content.split(" ");
const voiceChannel = message.member.voice.channel;
if (!voiceChannel)
return message.channel.send(
"You need to be in a voice channel to play music!"
);
const permissions = voiceChannel.permissionsFor(message.client.user);
if (!permissions.has("CONNECT") || !permissions.has("SPEAK")) {
return message.channel.send(
"I need the permissions to join and speak in your voice channel!"
);
}
const songInfo = await ytdl.getInfo(args[1]);
const song = {
title: songInfo.title,
url: songInfo.video_url
};
if (!serverQueue) {
const queueContruct = {
textChannel: message.channel,
voiceChannel: voiceChannel,
connection: null,
songs: [],
volume: 5,
playing: true
};
queue.set(message.guild.id, queueContruct);
queueContruct.songs.push(song);
try {
var connection = await voiceChannel.join();
queueContruct.connection = connection;
play(message.guild, queueContruct.songs[0]);
} catch (err) {
console.log(err);
queue.delete(message.guild.id);
return message.channel.send(err);
}
} else {
serverQueue.songs.push(song);
return message.channel.send(${song.title} has been added to the queue!
);
}
}
function skip(message, serverQueue) {
if (!message.member.voice.channel)
return message.channel.send(
"You have to be in a voice channel to stop the music!"
);
if (!serverQueue)
return message.channel.send("There is no song that I could skip!");
serverQueue.connection.dispatcher.end();
}
function stop(message, serverQueue) {
if (!message.member.voice.channel)
return message.channel.send(
"You have to be in a voice channel to stop the music!"
);
serverQueue.songs = [];
serverQueue.connection.dispatcher.end();
}
function play(guild, song) {
const serverQueue = queue.get(guild.id);
if (!song) {
serverQueue.voiceChannel.leave();
queue.delete(guild.id);
return;
}
const dispatcher = serverQueue.connection
.play(ytdl(song.url))
.on("finish", () => {
serverQueue.songs.shift();
play(guild, serverQueue.songs[0]);
})
.on("error", error => console.error(error));
dispatcher.setVolumeLogarithmic(serverQueue.volume / 5);
serverQueue.textChannel.send(Start playing: **${song.title}**
);
}` for music bot i am running my own cmds to it and thats the other code that i didnt put