Search code examples
pythondiscorddiscord.pybots

VoiceState always returning None as 'channel' value


I'm messing around creating a discord bot, but the VoiceState objetcs that I get always have the channel value to None.

intents = discord.Intents(messages=True, voice_states=True)
client = discord.Client(intents=intents)

@client.event
async def on_voice_state_update(member, before, after):
  print("Channel event", member, before.channel, after.channel)
  print(member.voice)

I'm not able to get the event channel values from after, before nor Member.voice.

Any suggetions? Is it bugged?

Thank you all!

Trying to get the channel from on_voice_state_update always returns None


Solution

  • To see the channels of a guild, you also need to enable the guilds intent, like this:

    intents = discord.Intents(messages=True, voice_states=True, guilds=True)
    

    Here is a list of all intents: https://discordpy.readthedocs.io/en/latest/api.html?highlight=intents#discord.Intents

    Hope this helps.