'Discord bot that modifies others' voice state throwing error when I get disconnected
I made a bot that disconnects, deafens, and mutes anyone who modifies my voice state. Here it is:
client = commands.Bot(command_prefix='!')
entries=[]
@client.event
async def on_voice_state_update(member, before, after):
if member != client.user:
return
if after.deaf or after.mute or not after.channel:
await member.edit(mute=False, deafen=False)
print("Voice state alter blocked.")
entries.clear()
async for entry in server.audit_logs(limit=2):
entries.append(entry)
perp = server.get_member_named(f'{entries[1].user.name}#{entries[1].user.discriminator}')
await perp.edit(mute=True, deafen=True, voice_channel=None, reason=random.choice(reason))
client.run(token)
It's supposed to work with someone disconnecting me as well, but when someone does kick me, this error gets thrown: discord.errors.HTTPException: 400 Bad Request (error code: 40032): Target user is not connected to voice.
The person who does it remains in the voice channel they're in, even though the error states that they're not.
Why is it throwing this error, even though the target is in a voice call?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
