-2

I'm looking to make a bot come online whenever a user joins a channel and go offline when a user leaves a channel. I'm quite new to discord.py but here's my code:

import discord
from discord.ext import commands

client = commands.Bot(command_prefix = '.')

@client.event
async def on_ready():
    await client.change_presence(status=discord.Status.offline)
    print("Bot ready")

@client.event
async def on_voice_state_update(member, before, after):
    if not before.channel:
        if after.channel.id == [""Channel ID 1""] or after.channel.id == [""Channel ID 2""]:
                await client.change_presence(status=discord.Status.online, activity=discord.Activity(type=discord.ActivityType.listening, name="users | Ready to mute"))
                print(f'{member.name} joined {after.channel.name}')
    elif before.channel and after.channel:
        if before.channel != after.channel:
            if after.channel.id == [""Channel ID 1""] or after.channel.id == [""Channel ID 2""]:
                if member.roles[1].name == "Admin" or member.roles[1].name == "Moderator":
                    await client.change_presence(status=discord.Status.online, activity=discord.Activity(type=discord.ActivityType.listening, name="users | Ready to mute"))
                    print(f'{member.name} joined {after.channel.name}')
    elif before.channel and not after.channel:
            if member.roles[1].name == "Admin" or member.roles[1].name == "Moderator":
                await client.change_presence(status=discord.Status.offline)
                print(f'{member.name} left {before.channel.name}')

client.run("Key")

I will, of course, replace ""Channel ID 1"" & ""Channel ID 2"" with the channel IDs and ""Key" with my authentication key.

The problem that I am having is that the events don't seem to be registered.

Thanks for any help!

1
  • 1
    A couple of changes, id is an int not a string as explained here. So you should be comparing channel.id against an integer, not a list item. Commented Oct 10, 2020 at 8:49

1 Answer 1

0

A couple of changes, id is an int not a string as explained here. So you should be comparing channel.id against an integer, not a list item.

– InsertCheesyLine

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.