ShadowNotFake
ShadowNotFake

Reputation: 114

Bot doesn't want to show id of a channel

I want bot to print id of the channel that member connected to.

@client.event
async def on_voice_state_update(member, before, after):
    channelid = discord.VoiceChannel.id
    print(f'{channelid}')

When I am joining this channel I get this:

<member 'id' of 'VoiceChannel' objects>

Upvotes: 0

Views: 88

Answers (1)

Nurqm
Nurqm

Reputation: 4743

Because you are trying to get VoiceChannel id, and VoiceChannel is a class, not an actual channel. For getting the id of the voice channel, you can use before.channel.id or after.channel.id. It depends on what you want to do. So you can change your code like this:

@client.event
async def on_voice_state_update(member, before, after):
    channelid = before.channel.id
    print(f'{channelid}')

As far as I know, if member joins the voice channel, then before.channel.id returns None and if member leaves the voice channel, then after.channel.id returns None.

Upvotes: 1

Related Questions