Skip to content
Advertisement

AttributeError: ‘NoneType’ object has no attribute ‘id’_

here is my code in the bot

@Bot.event
async def on_voice_state_update(member,before,after): #Создвние войс комнат
    if after.channel.id == &&&&&&&&&&&&&&&&&&:
        print(f'{member} зашёл в канал')
        for guild in Bot.guilds:
            maincategory = discord.utils.get(guild.categories, id=$$$$$$$$$$$$$$$$$$)
            channel2 = await guild.create_voice_channel(name=f'{member.display_name}`s Channel',category = maincategory)
            await channel2.set_permissions(member,connect=True,mute_members=True,move_members=True,manage_channels=True)
            await member.move_to(channel2)
            def check(x,y,z):
                return len(channel2.members) == 0
            await Bot.wait_for('voice_state_update',check=check)
            await channel2.delete()

And this is my error in the terminal

Traceback (most recent call last):
  File "C:UsersМаксAppDataLocalPackagesPythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0LocalCachelocal-packagesPython39site-packagesdiscordclient.py", line 343, in _run_event
    await coro(*args, **kwargs)
  File "C:UsersМаксDRACULA-rmsbot.py", line 108, in on_voice_state_update
    if after.channel.id == &&&&&&&&&&&&&&&&&&&&:
AttributeError: 'NoneType' object has no attribute 'id'

Please help me please, I can not solve this error myself, I use Python 39

Advertisement

Answer

not the most optimal way, but i guess you can use this:

if after:
    if after.channel:
             if after.channel.id == &&&&&&&&&&&&&&&&&&:
             //Your code here

It basically first checks if after is none, if its not then if after,channel is none? if its not then it will refer to it’s id

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement