question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@discordjs/voice not working in Digital Ocean app container

See original GitHub issue

Which package is this bug report for?

voice

Issue description

I’m having trouble creating a @discordjs/voice player

My problem is the code works fine when run locally, or in Docker container on my machine, but won’t run in a Digital Ocean app

As I mentioned it works as expected running on my machine, or in a Docker container on my machine, but fails silently in a Digital Ocean app container. It feels like this will be an utter pain to debug - hoping somebody here has some insight

Some Debug Output

[2022-03-25 00:05:11] [NW] [WS] >> {"op":0,"d":{"server_id":"----","user_id":"----","session_id":"----","token":"----"}}
[2022-03-25 00:05:11] [NW] state change:
[2022-03-25 00:05:11] from {"code":0,"ws":true,"connectionOptions":{"endpoint":"singapore10087.discord.media:443","serverId":"----","token":"----","sessionId":"----","userId":"----"},"udp":false}
[2022-03-25 00:05:11] to {"code":1,"ws":true,"connectionOptions":{"endpoint":"singapore10087.discord.media:443","serverId":"----","token":"----","sessionId":"----","userId":"----"},"udp":false}
[2022-03-25 00:05:11] [NW] [WS] << {"op":8,"d":{"v":4,"heartbeat_interval":13750.0}}
[2022-03-25 00:05:11] [NW] [WS] << {"op":2,"d":{"streams":[{"type":"video","ssrc":289778,"rtx_ssrc":289779,"rid":"","quality":0,"active":false}],"ssrc":289777,"port":50002,"modes":["aead_aes256_gcm_rtpsize","aead_aes256_gcm","xsalsa20_poly1305_lite_rtpsize","xsalsa20_poly1305_lite","xsalsa20_poly1305_suffix","xsalsa20_poly1305"],"ip":"35.213.188.143","experiments":["bwe_conservative_link_estimate","bwe_remote_locus_client","fixed_keyframe_interval"]}}
[2022-03-25 00:05:11] [NW] state change:
[2022-03-25 00:05:11] from {"code":1,"ws":true,"connectionOptions":{"endpoint":"singapore10087.discord.media:443","serverId":"----","token":"----","sessionId":"----","userId":"----"},"udp":false}
[2022-03-25 00:05:11] to {"code":2,"ws":true,"connectionOptions":{"endpoint":"singapore10087.discord.media:443","serverId":"----","token":"----","sessionId":"----","userId":"----"},"udp":true,"connectionData":{"ssrc":289777}}
[2022-03-25 00:05:25] [NW] [WS] >> {"op":3,"d":1648166725326}
[2022-03-25 00:05:25] [NW] [WS] << {"op":6,"d":1648166725326}
[2022-03-25 00:05:39] [NW] [WS] >> {"op":3,"d":1648166739077}
[2022-03-25 00:05:39] [NW] [WS] << {"op":6,"d":1648166739077}
[2022-03-25 00:05:52] [NW] [WS] >> {"op":3,"d":1648166752827}
[2022-03-25 00:05:52] [NW] [WS] << {"op":6,"d":1648166752827}
[2022-03-25 00:06:06] [NW] [WS] >> {"op":3,"d":1648166766577}
[2022-03-25 00:06:06] [NW] [WS] << {"op":6,"d":1648166766577}
[2022-03-25 00:06:11] Error: Cannot perform IP discovery - socket closed
[2022-03-25 00:06:11]     at Socket.<anonymous> (/app/out/node_modules/@discordjs/voice/dist/index.js:299:15)
[2022-03-25 00:06:11]     at Object.onceWrapper (node:events:645:28)
[2022-03-25 00:06:11]     at Socket.emit (node:events:538:35)
[2022-03-25 00:06:11]     at socketCloseNT (node:dgram:746:8)
[2022-03-25 00:06:11]     at processTicksAndRejections (node:internal/process/task_queues:82:21)
[2022-03-25 00:06:14] [NW] [WS] << {"op":5,"d":{"user_id":"----","ssrc":289794,"speaking":0}}
[2022-03-25 00:06:20] [NW] [WS] >> {"op":3,"d":1648166780327}
[2022-03-25 00:06:20] [NW] [WS] << {"op":6,"d":1648166780327}

Code sample

import {
  AudioPlayerStatus,
  createAudioPlayer,
  createAudioResource,
  joinVoiceChannel,
  NoSubscriberBehavior,
  VoiceConnection,
} from "@discordjs/voice";
import Config from "config";
import path from "path";
import { Global } from "../Global";

export default class VoiceChannelController {
  static player = createAudioPlayer({
    behaviors: { noSubscriber: NoSubscriberBehavior.Pause },
  });

  static get resource() {
    const p = path.join(__dirname, "..", "sounds", "test-sound.webm");
    return createAudioResource(p);
  }

  static connection: VoiceConnection;

  static async init() {
    const bb = Global.bot("VOICE_BOT");
    const channel = await bb.guild.channels.fetch(Config.channelId("VOICE"));

    if (channel === null) {
      throw new Error("Cannot find voice channel.");
    }

    this.connection = joinVoiceChannel({
      channelId: channel.id,
      guildId: channel.guild.id,
      debug: true,
      adapterCreator: channel.guild.voiceAdapterCreator,
      selfDeaf: false,
    });

    this.connection.subscribe(this.player);

    this.connection.on("debug", (...args) => {
      console.log(...args);
    });

    this.connection.on("error", (...args) => {
      console.log(...args);
    });

    this.player.play(this.resource);

    this.player.on(AudioPlayerStatus.Idle, () => {
      this.player.play(this.resource);
    });
  }
}

Package version

0.8.0

Node.js version

16.14.0

Operating system

OSX, Docker Alpine

Priority this issue should have

Medium (should be fixed soon)

Which partials do you have configured?

No Partials

Which gateway intents are you subscribing to?

GuildVoiceStates

I have tested this issue on a development release

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
JakeEldercommented, Mar 26, 2022

@JMTK - I tried every region. None of them worked unfortunately. I am using SGP generally.

1reaction
JMTKcommented, Mar 25, 2022

@JakeElder mind sharing your Dockerfile? I’m also using Docker for app containers on DO but not for voice.

Also, which region are you using? There’s a similar issue that had issues with certain regions https://github.com/discordjs/discord.js/issues/3137

Read more comments on GitHub >

github_iconTop Results From Across the Web

docker - Error when connecting to @discord/voice API from ...
I have deployed a Node.js app as a Web Application in Digitalocean using the standard build & deploy process. Within this app I'm...
Read more >
How To Build a Discord Bot with Node.js
Bots can perform various actions such as sending messages to servers, DM-ing users, moderating servers, and playing audio in voice chats. This ...
Read more >
How to Host a Discord Bot 24/7 on Digital Ocean ($100 in free ...
Digital Ocean is the hosting company I use for my own Discord bots. In this video tutorial I go over how to how...
Read more >
How to Host Discord Bot on Digital Ocean, Amazon AWS or ...
In this post, we will not dive into developing Discord bots. Instead, we will use a freely available ... Setup a VPS Server...
Read more >
memory access out of bounds Error in Discord.JS hosted ...
Make sure your digital-ocean enviornment supports web assembly ( it probably does since you said it was working fine initially although if not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found