Discord.js: Cannot get voiceChannel playfile() example to work

Created on 13 Sep 2016  路  6Comments  路  Source: discordjs/discord.js

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.

question (please use Discord instead) voice

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 馃帀

All 6 comments

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()

Was this page helpful?
0 / 5 - 0 ratings

Related issues

LLamaFTL picture LLamaFTL  路  3Comments

tom-barnes picture tom-barnes  路  3Comments

DatMayo picture DatMayo  路  3Comments

ghost picture ghost  路  3Comments

Acaretia picture Acaretia  路  3Comments