Discord.js: Music looping isn't working

Created on 22 Jan 2018  ·  13Comments  ·  Source: discordjs/discord.js

Please describe the problem you are having in as much detail as possible:

Music looping isn't working.

Include a reproducible code sample here, if possible:

const Discord = require('discord.js');
const client = new Discord.Client();
const broadcast = client.createVoiceBroadcast();
const fs = require('fs');


client.login('td4rjtp4uit590rsuwuw3590s32uwrpaupiw');

client.on('message', async message => {
  // Voice only works in guilds, if the message does not come from a guild,
  // we ignore it
  if (!message.guild) return;

  if (message.content === '/fire_join') {
    // Only try to join the sender's voice channel if they are in one themselves
    if (message.member.voiceChannel) {
      const connection = await message.member.voiceChannel.join();
      connection.playBroadcast(broadcast);
      message.reply('Connecting..');
    } else {
      message.reply('You need to join a voice channel first!');
    }
  }
});

var dispatcher = broadcast.playFile('./EXPLOSION.opus');
  dispatcher.on('end', () => {
    dispatcher = broadcast.playFile('./EXPLOSION.opus');
  });

Further details:

  • discord.js version: npm latest
  • node.js version: latest
  • Operating system: win10 pro workstation
  • Priority this issue should have – please be realistic and elaborate if possible:

  • [ ] I found this issue while running code on a __user account__
  • [ ] I have also tested the issue on latest master, commit hash:
question (please use Discord instead)

Most helpful comment

You were already answered. Don't open an issue if you won't take answers. Besides, go to the server for these questions.

All 13 comments

seems work at first but it stopped suddenly

The issue tracker is only for bug reports and enhancement suggestions. If you have a question, please ask it in the Discord server instead of opening an issue – you will get redirected there anyway.

@devdutchy It's bug report, check it

You didn't even show us any errors, you only told us something is not working with some code. We cannot help you with only that 🤷‍♂️

events.js:142
      throw err;
      ^

Error [ERR_UNHANDLED_ERROR]: Unhandled error. ([object Object])
    at Client.emit (events.js:140:19)
    at WebSocketConnection.onError (C:\Users\Maru\Desktop\explotion\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:371:17)
    at WebSocket.onError (C:\Users\Maru\Desktop\explotion\node_modules\ws\lib\event-target.js:128:16)
    at WebSocket.emit (events.js:159:13)
    at WebSocket.finalize (C:\Users\Maru\Desktop\explotion\node_modules\ws\lib\websocket.js:190:41)
    at TLSSocket.emit (events.js:159:13)
    at onwriteError (_stream_writable.js:420:12)
    at onwrite (_stream_writable.js:442:5)
    at _destroy (internal/streams/destroy.js:39:7)
    at TLSSocket.Socket._destroy (net.js:575:3)

Maybe you should handle the error event?

@iCrawl There is any error? and sometimes returns error, and sometimes stopped loop without any error

Like Crawl said, maybe you should handle the error event.

The error event should always be handled.

client.on('error', console.error)

sure but if i even created error handler, music looping is stopped

@U-siro you clearly not understand that handling the error might help you finding out why your loop stopped and then you could fix that problem since it doesn't sound thats its d.js fault (most likely something wrong in your loop code)

yep, but no error is returned in my error handler so I really no idea about it

You were already answered. Don't open an issue if you won't take answers. Besides, go to the server for these questions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Dmitry221060 picture Dmitry221060  ·  3Comments

Lombra picture Lombra  ·  3Comments

ghost picture ghost  ·  3Comments

tom-barnes picture tom-barnes  ·  3Comments

iCrawl picture iCrawl  ·  3Comments