Closed rxsto closed 4 months ago
Could this be a race condition issue on discord's end? It seems like simply delaying the request to speak a bit solves the problem for me.
Interesting catch! And yes indeed, delaying the request to speak seems to solve this problem, at least sometimes. The durations I tested delaying the request to speak with seemed quite arbitrary, since sometimes the exact same amount of delay failed to mitigate the issue, and at other times it worked perfectly fine.
Using 500
milliseconds as the delay seems to be quite consistent though.
Regardless, we're pretty unsure as to how to figure out, if this problem could potentially be on Discord's end.
It seems like discord has issues if you send it before the audio gateway is fully connected, you can listen for this using ConnectionListener.
audioManager.setConnectionListener(new ConnectionListener() {
@Override
public void onStatusChange(ConnectionStatus status) {
if (status == CONNECTED) {
channel.requestToSpeak().queue();
}
}
});
That's it! Awaiting the CONNECTED
status resolves this issue for us. Again, interesting catch - it doesn't really make sense how a requestToSpeak
request can cause the audio streaming to break.
Thanks for figuring this out! ~ Cheers
General Troubleshooting
Version of JDA
5.0.0-beta.22
Expected Behaviour
When joining a stage, the bot should be able to stream audio in all cases.
The original discussion about this behavior started in a help post on the JDA Discord server: https://discord.com/channels/125227483518861312/1229423364385538150/1229423364385538150
While building the reproduction repo we were able to further define the underlying issue, as this only happens in very specific cases.
(Scenario 1) The bot is unable to send audio to the stage channel, when these steps are followed:
!play
in a text channel The bot will the join the stage and automatically be promoted to a speaker as it has the moderator permissions, but it will not transmit any audio.(Scenario 2) This issue can be resolved by using following workaround:
!play
in a text channel!kill
and repeating all the steps from Scenario 1 will allow the bot to properly stream audio regardless. This might be due to the bot having the stage instance loaded properly before.(Scenario 3) The bot is able to steam audio in an active stage, as long as it has started it itself:
!play
and let the bot join the stage as well as start it The bot will be promoted to being a speaker immediately, the same as in Scenario 1, but is able to start streaming audio since the stage has been created by itself.When disconnecting and killing the bot application (as in restarting) whilst it was able to properly stream audio to the channel as a stage moderator, and getting it to play audio again via
!play
, it will fail again. This might as well be related to the same issue explained in the workaround from Scenario 2.Code Example for Reproduction Steps
Code for JDABuilder or DefaultShardManagerBuilder used
Exception or Error