Reputation: 59
I'm trying to get my discord bot to disconnect users who get moved to the AFK channel. all works well with that except it tries to disconnect users who just enter talk channels, not just when you get moved to the AFK channel. I have to set permissions to not allow the bot to move or disconnect from those channels, so it keeps pulling up Missing permissions. Would love it to ignore those other voice channels.
i'm not sure how to exclude a voice channel so I tried
if discord.VoiceChannel.id == id:
return
to no avail. I've tried setting the bot to not see those channels through discord but it still does and still tries to disconnect people.
@client.event
async def on_voice_state_update(member = discord.Member, before = discord.VoiceState.channel, after = discord.VoiceState.afk):
await member.move_to(channel = None, reason = None)
Im guessing it's something basic but not sure how to ignore the other channels.
I thought the API said the before = discord.VoiceState.channel
refers to a members recent voice channel, none if they weren't in one, then when they go to the AFK channel, after = discord.VoiceState.afk
it would disconnect. Am i interpreting that wrong? I'm obviously missing something
Upvotes: 0
Views: 2534
Reputation: 4056
From the API, on_voice_state_update
will give you three things:
member
who had changed their voice stateVoiceState
before the member did something.VoiceState
after the member did something.And by "did something", its means this:
(Aka literally what the API states)
What you are looking out for is the VoiceState
after the change has occured. And in the API, it states that VoiceState
has a property called afk
which checks if the member is in the afk channel.
Your code would look something like this:
@client.event
async def on_voice_state_update(member, before, after):
# If the user moved to the afk channel.
if after.afk:
# Do something about the user in afk channel.
### Use the codes below if you want to check if the user moved to a channel of the ID:
if after.channel is None:
# The user just simply left the channel.
# (Aka he did not switch to another voice channel.)
elif after.channel.id == ID_OF_CHANNEL_HERE:
# Do something about the user that just joined the channel with the respective ID
Upvotes: 2
Reputation: 2907
What about reading the docs? Here it is My idea is that you can do
if discord.VoiceClient.channel.id == id:
return
But I have a feeling this is wrong.
Upvotes: 0