-1

Like the title says UnhandledPromiseRejectionWarning: Error: No video id found is what it says on the console after I sent a command: !join {link}. UnhandledPromiseRejectionWarning: Unhandled promise rejection shows up too.

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;
Federico Grandi
  • 6,785
  • 5
  • 30
  • 50
ShidouK
  • 7
  • 2

1 Answers1

0

An unhandled Promiserejection happens, when you promise gets rejected and you dont catch the error which it is producing. To get the error, which you want to handle, you may put a .catch statement after the .then statement. e.G:

            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) });

Maybe that will help you for your error handling.

Lukas Germerott
  • 361
  • 3
  • 17
  • Would be nice, if you vote my answer as solution, so that other users can see, what the solution is, without looking up the comments – Lukas Germerott Jan 16 '19 at 11:59