Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When bot is moved to another voice channel while playing, stops playing audio (code: 4014) #30

Open
milosz08 opened this issue Nov 20, 2024 · 0 comments

Comments

@milosz08
Copy link

Hi, when I move bot from channel to channel during active audio playback (doesn't matter if manually or via JDA) player is updated with a new endpoint, token, etc. but does not play audio.

I did a little digging in the code and noticed that this is due to the interception of the WebSocketClosedEvent event. Suggesting by error codes it appears that bot has disconnected from the channel (which is logical, since it connects to another one).

  is Message.EmittedEvent.WebSocketClosedEvent -> {
      // These codes represent an invalid session
      // See https://discord.com/developers/docs/topics/opcodes-and-status-codes#voice-voice-close-event-codes

      if (event.code == 4004 || event.code == 4006 || event.code == 4009 || event.code == 4014) {
          logger.debug("Node '{}' received close code {} for guild {}", node.name, event.code, event.guildId)
          // TODO: auto-reconnect?
          node.destroyPlayerAndLink(event.guildId.toLong()).subscribe()
      }
  }
  else -> {}

Lavalink logs:

2024-11-19 12:39:25 2024-11-19T11:39:25.104Z  INFO 1 --- [Lavalink] [  XNIO-1 task-2] l.server.io.RequestLoggingFilter         : GET /v4/loadtracks?identifier=https%3A%2F%2Fsoundcloud.com%2Fgermanariganello%2Fteardrop-massive-attack, client=172.28.0.1
2024-11-19 12:39:25 2024-11-19T11:39:25.113Z  INFO 1 --- [Lavalink] [  XNIO-1 task-2] l.server.io.RequestLoggingFilter         : PATCH /v4/sessions/8wcsvnv97stnscvy/players/864847983246180363?noReplace=false, client=172.28.0.1, payload={"track":{"encoded":"QAABQwMAG1RlYXJkcm9wIOKXjyBNYXNzaXZlIEF0dGFjawAOR2VyIEFyaWdhbmVsbG8AAAAAAAUpPgBxTzpodHRwczovL2FwaS12Mi5zb3VuZGNsb3VkLmNvbS9tZWRpYS9zb3VuZGNsb3VkOnRyYWNrczoxNTIyNzMyMTUvZjQ3YTVjZDAtNzMwOC00YzMzLTgxMDYtODM1Y2JhZDdjNDQyL3N0cmVhbS9obHMAAQA/aHR0cHM6Ly9zb3VuZGNsb3VkLmNvbS9nZXJtYW5hcmlnYW5lbGxvL3RlYXJkcm9wLW1hc3NpdmUtYXR0YWNrAQA/aHR0cHM6Ly9pMS5zbmRjZG4uY29tL2FydHdvcmtzLTAwMDA4MTExMzMyNy16czJ3Zm0tb3JpZ2luYWwuanBnAAAKc291bmRjbG91ZAAAAAAAAAAA","userData":{"authorId":611676017345560582}},"position":0}
2024-11-19 12:39:28 2024-11-19T11:39:28.335Z  INFO 1 --- [Lavalink] [  XNIO-1 task-2] l.server.io.RequestLoggingFilter         : DELETE /v4/sessions/8wcsvnv97stnscvy/players/864847983246180363, client=172.28.0.1
2024-11-19 12:39:28 2024-11-19T11:39:28.590Z  INFO 1 --- [Lavalink] [  XNIO-1 task-2] l.server.io.RequestLoggingFilter         : PATCH /v4/sessions/8wcsvnv97stnscvy/players/864847983246180363?noReplace=false, client=172.28.0.1, payload={"voice":{"token":"9385e9a9788f62c2","endpoint":"warsaw10038.discord.media:443","sessionId":"c46c9d81c963ecce64ec74a4d1df599a"}}
2024-11-19 12:39:38 2024-11-19T11:39:38.981Z  INFO 1 --- [Lavalink] [  XNIO-1 task-2] l.server.io.RequestLoggingFilter         : DELETE /v4/sessions/8wcsvnv97stnscvy/players/864847983246180363, client=172.28.0.1
2024-11-19 12:39:39 2024-11-19T11:39:39.210Z  INFO 1 --- [Lavalink] [  XNIO-1 task-2] l.server.io.RequestLoggingFilter         : PATCH /v4/sessions/8wcsvnv97stnscvy/players/864847983246180363?noReplace=false, client=172.28.0.1, payload={"voice":{"token":"9385e9a9788f62c2","endpoint":"warsaw10050.discord.media:443","sessionId":"c46c9d81c963ecce64ec74a4d1df599a"}}

When I remove the 4014 code it seems to work properly (it does not remove the player and link, and player on the lavalink server is updated and playing audio)

  if (event.code == 4004 || event.code == 4006 || event.code == 4009) {
      logger.debug("Node '{}' received close code {} for guild {}", node.name, event.code, event.guildId)
      // TODO: auto-reconnect?
      node.destroyPlayerAndLink(event.guildId.toLong()).subscribe()
  }

Lavalink logs:

2024-11-20 02:35:20 2024-11-20T01:35:20.590Z  INFO 1 --- [Lavalink] [  XNIO-1 task-2] l.server.io.RequestLoggingFilter         : GET /v4/loadtracks?identifier=https%3A%2F%2Fsoundcloud.com%2Fraulrey_98%2Fanimals-nightcore, client=172.28.0.1
2024-11-20 02:35:20 2024-11-20T01:35:20.700Z  INFO 1 --- [Lavalink] [  XNIO-1 task-2] l.server.io.RequestLoggingFilter         : PATCH /v4/sessions/zm6yqr2xptsd8kck/players/864847983246180363?noReplace=false, client=172.28.0.1, payload={"track":{"encoded":"QAABKwMAE0FuaW1hbHMgKE5pZ2h0Y29yZSkAClJBVUxSRVlfOTgAAAAAAAMFowBxTzpodHRwczovL2FwaS12Mi5zb3VuZGNsb3VkLmNvbS9tZWRpYS9zb3VuZGNsb3VkOnRyYWNrczo0MzM5MDc3MTIvMjVhN2FmNTktMDk4Zi00Mjk4LTk5ZGMtMDM2MzRkNTRiOGIzL3N0cmVhbS9obHMAAQAzaHR0cHM6Ly9zb3VuZGNsb3VkLmNvbS9yYXVscmV5Xzk4L2FuaW1hbHMtbmlnaHRjb3JlAQA/aHR0cHM6Ly9pMS5zbmRjZG4uY29tL2FydHdvcmtzLTAwMDMzODg0NjIyOS11cTdkZDYtb3JpZ2luYWwuanBnAAAKc291bmRjbG91ZAAAAAAAAAAA","userData":{"requester":611676017345560582}},"position":0,"volume":35}
2024-11-20 02:35:20 2024-11-20T01:35:20.798Z  INFO 1 --- [Lavalink] [  XNIO-1 task-2] l.server.io.RequestLoggingFilter         : PATCH /v4/sessions/zm6yqr2xptsd8kck/players/864847983246180363?noReplace=false, client=172.28.0.1, payload={"voice":{"token":"a5fad6235ca16cf6","endpoint":"warsaw10015.discord.media:443","sessionId":"193d2b7193b25b71a66bd6393633a2d2"}}
2024-11-20 02:35:54 2024-11-20T01:35:54.085Z  INFO 1 --- [Lavalink] [  XNIO-1 task-2] l.server.io.RequestLoggingFilter         : PATCH /v4/sessions/zm6yqr2xptsd8kck/players/864847983246180363?noReplace=false, client=172.28.0.1, payload={"voice":{"token":"a5fad6235ca16cf6","endpoint":"warsaw10070.discord.media:443","sessionId":"193d2b7193b25b71a66bd6393633a2d2"}}

This above solution is not very useful, because it won't capture in this way voice channel removed event, kicking bot from server event and finally doesn't remove player from the Lavalink server.

I wonder if the player is definitely updated with the new Discord sound gateway. My guess is that correctly one would have to delete player and create a new one. Is there any plan to implement changing the channel during audio playback function? If not how to handle this other than removing error code from if statement.

Lavalink-client version: 3.1.0
Lavalink:

Version:        4.0.8
Build time:     20.09.2024 20:20:10 UTC
Branch          HEAD
Commit:         2946608
Commit time:    20.09.2024 20:17:58 UTC
 JVM:            18.0.2.1
Lavaplayer      2.2.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant