Making a discord bot move a member to the afk channel once they deafen

Viewed 331

ok so basically I want to make a bot to move a user to afk as soon as they deafen, I know very little about coding and wanted some help.

all I really want is for it to do is to scan all voice channels and move any deafened user it sees to the afk channel

here is the code i have:

     channel = self.bot.get_channel(800674042247118878)
     if after.deaf and after.channel:
        await member.move_to(.afkChannelId);

again I have absolutely no clue how to code and am basically just using what I could find

ty for the help <3

1 Answers

You should check VOICE_STATE_UPDATE. This event is raised when a user's voice state changes. This includes when a user joins, leaves, or moves between voice channels, as well as their mute and deaf status for themselves and on the server.

@bot.event
async def on_voice_state_update(member, before, after):
    if member.VoiceState.self_deaf:
         await member.move_to(afkchannel)
Related