disnake icon indicating copy to clipboard operation
disnake copied to clipboard

`on_voice_state_update` is sometimes fired with identical `before` and `after` states

Open shiftinv opened this issue 3 years ago • 1 comments

Summary

The on_voice_state_update event is very rarely (a few times a day) fired with identical before and after states, with VoiceState.channel = None in both instances.

Details

  • This appears to occur shortly before a member leaves a voice channel
  • The passed member and its associated guild aren't consistent
  • It happens irregularly, some days don't see it at all, while it sometimes happens several times a day

It's not a new bug and was already happening in dpy as well; either the API is misbehaving, or voice state caching has an obscure bug (which is more likely, imho).

Speculation

For both states' channels to be None, the channel here must've been None: https://github.com/DisnakeDev/disnake/blob/65e29bea2a93409a5feb9a5d35637eddbe8470a7/disnake/guild.py#L385

Possible explanations for this include:

  1. The API sent two events when a user disconnected
  2. A member joined voice (before.channel = None expected) but the channel with that specific channel_id wasn't cached, hence after.channel = None as well (unlikely)
  3. The channel_id itself was actually None, which would indicate that the member is disconnecting from voice (after.channel = None expected, before.channel shouldn't be None)

In the third case, before.channel = None can happen under one of these conditions:

  • The voice state wasn't cached at all before, so it's assumed that the member is joining voice (line 399)
  • The voice state was cached, but with .channel = None set when it was created, which would probably mean that the channel wasn't cached at creation time (don't think that's possible)

Context

Some more details and discussion here: https://discord.com/channels/808030843078836254/883342278280745030/926203235994316851

shiftinv avatar Dec 31 '21 11:12 shiftinv

I got in contact with a user who invoked this same issue and asked them to precisely state what actions they took. They stated the following:

my servers voice channel glitches so i clicked randomly on another server which in this case was xqc's server and just joined vc and insta left and joined my own servers vc, i did that twice

In this scenario, it makes sense for before.channel to be None (because the bot isn't present in the source guild), but it doesn't make sense for after.channel to be None (because the bot is present in the destination guild). From on_voice_state_update's perspective, this should be identical to a user joining a voice channel for the first time.

I attempted to reproduce this by hopping between voice channels in two different guilds, where a bot is present in one guild but not the other. I was not able to reproduce this issue, either in a dev environment (low scale) or production environment (higher scale).

ChristopherJHart avatar Dec 31 '21 13:12 ChristopherJHart