izy521 / discord.io

A small, single-file library for creating DiscordApp clients from Node.js or the browser
https://discord.gg/0MvHMfHcTKVVmIGP
MIT License
535 stars 155 forks source link

bot.joinVoiceChannel crashes the bot #277

Closed JubJub623D closed 6 years ago

JubJub623D commented 6 years ago

When the bot is running and the part of the code that uses bot.joinVoiceChannel is called, it returns this error message:

Error: Cannot find the server related to the channel provided: 468158477064470500 at handleErrCB (C:\Users\HKim\node_modules\discord.io\lib\index.js:1394:25) at DiscordClient.DCP.joinVoiceChannel (C:\Users\HKim\node_modules\discord.io\lib\index.js:1327:24) at DiscordClient.<anonymous> (C:\Users\HKim\bot\bot.js:184:22) at emitMany (events.js:147:13) at DiscordClient.emit (events.js:224:7) at DiscordClient.handleWSMessage (C:\Users\HKim\node_modules\discord.io\lib\index.js:1848:11) at emitTwo (events.js:126:13) at WebSocket.emit (events.js:214:7) at Receiver.ontext (C:\Users\HKim\node_modules\ws\lib\WebSocket.js:841:10) at C:\Users\HKim\node_modules\ws\lib\Receiver.js:536:18

This is the code that's throwing the error:

bot.joinVoiceChannel(468158477064470549, function(error, events) { if (error) return console.error(error); bot.getAudioContext(468158477064470549, function(error, stream) { if (error) return console.error(error); fs.createReadStream('Wonderwall.mp3').pipe(stream); stream.on('done', function() { bot.leaveVoiceChannel(468158477064470549, function(error, events){}); }); }); });;

EDIT: Also, how can I fix the formatting on this post?

ItsShadowCone commented 6 years ago

All id's in discord must be used as string in javascript you need to call it like bot.joinVoiceChannel('your id',....

The issue is, in your example you give the id 468158477064470549 but because of integer precision d.io sees 468158477064470500, which probably isn't a valid ID

JubJub623D commented 6 years ago

Thank you!