Search code examples
c#eventsdiscorddiscord.net

Discord.net: UserVoiceStateUpdated Event not fired when User initially connects to voice channel


I'm trying to have my bot recognize when any guild member joins a specific voice channel and then react to it. I tried to do this by subscribing to the UserVoiceStateUpdated event. This basically works as expected, however when a user first joins any voice channel, the event is not fired. When the user then switches from one voice channel to another, it works fine. As soon as you completely disconnect the user from voice and reconnect it once again requires changing the voice channel before my event handler is executed.

Am I doing something wrong? Is this the intended behavior? If so, can I somehow achieve this in another way?


Just to clarify again, this is what I'm doing and how the bot reacts to it:

  1. User connects to voice - UserVoiceStateUpdated is not fired
  2. User then switches to another voice channel - UserVoiceStateUpdated triggers my event handler correctly
  3. User switches voice channel once again - UserVoiceStateUpdated triggers again
  4. User disconnects from voice completely - UserVoiceStateUpdated triggers
  5. User reconnects to any voice channel - UserVoiceStateUpdated handler is not executed
  6. User switches voice channels - UserVoiceStateUpdated triggers as expected

Tried with both a .net Framework 4.7 and .net Core 2.0, as well as Discord.net versions 1.0, 1.0.1 and 1.0.2. Always the same.


Solution

  • So after adding some more logging I found that every time the event did not trigger this message was logged: "A UserVoiceStateUpdated handler is blocking the gateway task."

    I then started completely from scratch, created a new discord app, bot user, etc. and it worked. I can't really explain how that solved the problem but it did.