discordjs / discord.js

A powerful JavaScript library for interacting with the Discord API
https://discord.js.org
Apache License 2.0
25.47k stars 3.97k forks source link

problem changing the region while bot is playing opus stream #3839

Closed Zhet1 closed 4 years ago

Zhet1 commented 4 years ago

Please describe the problem you are having in as much detail as possible: if the bot is playing an opus stream and i change the server region, the bot is trigger the following error: 'Failed to send a packet Error: Tried to send a UDP packet, but there is no socket available.' this error make the bot follow playing music, but no make sounds, because cant renove the new socket ip

Include a reproducible code sample here, if possible:

async function playSong(guild, song){ 
    const serverqueue=queue.get(guild.id);
    if(!song){
        serverqueue.voiceChannel.leave();
        queue.delete(guild.id);
        return;
    }

    if(serverqueue.destroy === true){
        serverqueue.voiceChannel.leave();
        queue.delete(guild.id);
        return;
    }

    const dispatcher=serverqueue.connection.playOpusStream(await ytdl(song.url,{filter:'audioonly',quality:'highestaudio',highWaterMark: 1024 * 1024 * 32}),{bitrate: 192000 ,seek: serverqueue.seek})
    .on('debug',info=>{
        console.log("debug "+info);
        if(info == 'Failed to send a packet Error: Tried to send a UDP packet, but there is no socket available.'){
            if(!serverqueue.dispatcher.paused){
                serverqueue.dispatcher.pause();
            }
            serverqueue.seek = Math.round(serverqueue.dispatcher.time / 1000 % 60 % 60);
            serverqueue.reset = true;
            serverqueue.dispatcher.end();
        }else{
            console.log("debug "+info);
        }       
    })
    .on('speaking',estado=>{
        console.log("speak "+estado);
    }).on('failed',err=>{
        console.log("failed "+err);
    })    
    .on('end',reason=>{
        console.log("end "+reason)
        if(serverqueue.reset === true){
            setTimeout(()=>{
                serverqueue.voiceChannel.leave();
                serverqueue.voiceChannel.join();
                playSong(guild,serverqueue.songs[0]);
            }, 2000);
            return;
        }

        serverqueue.songs.shift();
        if(serverqueue.destroy === true){
            serverqueue.voiceChannel.leave();
            queue.delete(guild.id);
            return;
        }
        playSong(guild,serverqueue.songs[0]);
    }).on('reconnecting',info=>{
        console.log("reco "+info)
    })
    .on('newSession',newID=>{
        console.log("id "+newID)
    })
    .on('disconnect',info=>{
        console.log("disco "+info)
    });
    dispatcher.setVolumeLogarithmic(serverqueue.volume/5);
    serverqueue.dispatcher=dispatcher;
    if(serverqueue.reset === true){
        serverqueue.seek=0;
        serverqueue.reset=false;
        return;
    }
    serverqueue.textChannel.send(`Ahora Reproduciendo: ${song.titulo}`);
}

error:

Failed to send a packet Error: Tried to send a UDP packet, but there is no socket available.

The error is only trigger on the current song and only is capture in the debug method when the stream is on resume in the current song, if you start the next song the problem is solved

discord.js version: 11.5.1 Node.js version: 13.7.0 Operating system: Windows 10 and Ubuntu 18.04 Priority: Medium ffmpeg version: 3.2.2-3

iCrawl commented 4 years ago

This is not using the issue template, please update or close.

Zhet1 commented 4 years ago

This is not using the issue template, please update or close.

updated

Zhet1 commented 4 years ago

solved in version 12.0.1