With discord.[email protected], I'm doing:
var Discord = require('discord.js');
var bot = new Discord.Client();
bot.login("token").then().catch(err => console.log(err));
bot.on('ready', (message) => {
var voiceChannel = bot.channels.filter(g => {
return g.type == 'voice' && g.name == 'General';
}).first();
voiceChannel.join()
.then(connection => {
console.log('playing');
const dispatcher = connection.playFile('sound.mp3');
})
.catch(err => console.log(err));
});
The bot correctly joins the audio channel, but the 'playing' message is never displayed nor audio played.
I'm getting this output after 15 seconds:
Error: Connection not established within 15 seconds.
at Array.client.setTimeout (/home/v/tjs/node_modules/discord.js/src/client/voice/ClientVoiceManager.js:121:43)
at Timeout.setTimeout (/home/v/tjs/node_modules/discord.js/src/client/Client.js:163:16)
at tryOnTimeout (timers.js:232:11)
at Timer.listOnTimeout (timers.js:202:5)
Is this the new correct way of doing this ? Code for playing sample is taken from new documentation.
There could be a number of causes, first of all your path to your file should be './sound.mp3' as the ./ indicates the current folder. If that does not fix it please join the discord.js support server and we'll help troubleshoot the issue.
This would happen when your connection is _really_ bad, or if you have network issues. It would happen when the client fails to connect a voice WebSocket or fails to set up UDP.
The reason was firewall;
on audio chat join, a UDP connection is done for audio (on port 52710 for me)
firewall was blocking, connection never made, .then() code never executed etc etc.
Hope this will help someone some day 馃帀
Glad you fixed it :smile:
this will only join the general channel of the server .. .. how can we make the bot join to the channel the user is in .?
@tuneitbaby it's a bit late but here is the answere message.member.voiceChannel.join()
Most helpful comment
The reason was firewall;
on audio chat join, a UDP connection is done for audio (on port 52710 for me)
firewall was blocking, connection never made, .then() code never executed etc etc.
Hope this will help someone some day 馃帀