就像标题说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;
答案 0 :(得分:0)
当您承诺被拒绝并且没有抓住它产生的错误时,就会发生未处理的Promiserejection。要获取要处理的错误,可以在.catch
语句之后放置.then
语句。例如:
message.member.voiceChannel.join()
.then(connection =>{
var server = servers[message.guild.id];
message.reply("Succesfully Joined!");
server.queue.push(args);
Play(connection, message);
}).catch(e => { console.log(e) });
也许可以帮助您处理错误。