就像标题所说UnhandledPromiseRejectionWarning: Error: No video id found
的是我发送命令后在控制台上所说的:!join {link}
。
UnhandledPromiseRejectionWarning: Unhandled promise rejection
也出现了。
const commando = require('discord.js-commando'); const YTDL = require('ytdl-core');
function Play(connection, message) {
var server = servers[message.guild.id];
server.dispatcher = connection.playStream(YTDL(server.queue[0], {filter: "audioonly"}));
server.queue.shift();
server.dispatcher.on("end", function()
{
if(server.queue[0])
{
Play(connection,message);
}
else
{
connection.disconnect();
}
}); }
class JoinChannelCommand extends commando.Command {
constructor(client)
{
super(client,{
name: 'join',
group: 'music',
memberName: 'join',
description: 'Join the voice channel'
});
}
async run(message, args)
{
if(message.member.voiceChannel)
{
if(!message.guild.voiceConnection)
{
if(!servers[message.guild.id])
{
servers[message.guild.id] = {queue: []}
}
message.member.voiceChannel.join()
.then(connection =>{
var server = servers[message.guild.id];
message.reply("Succesfully Joined!");
server.queue.push(args);
Play(connection, message);
})
}
}
else
{
message.reply("You need to be in a voice channel to invite me Baka!")
}
}
}
module.exports = JoinChannelCommand;