D
D
darud2021-10-14 09:55:26
Python
darud, 2021-10-14 09:55:26

I wanted to make it so that the bot gave out the role by reaction and also took it away, but in the code there is such an error “AttributeError: 'Bot' object has no attribute guild”?

@client.event
async def on_raw_reaction_add(payload):
    message_id=payload.message_id
    if message_id == 0:
        guild_id = payload.guild_id
        guild = discord.utils.find(lambda g : g.id == guild_id, client.guild)  #говорит что тут ошибка

        if payload.emoji.name == 'yellow_square':
            role=discord.utils.get(guild.roles, name='ChSW LAND')
        elif payload.emoji.name == 'purple_square':
            role=discord.utils.get(guild.roles, name='LASTTASK')
        else:
            role=discord.utils.get(guild.roles, name=payload.emoji.name)

        if role is not None:
            member=discord.utils.find(lambda m : m.id == payload.user.id, guild.members)
            if member is not None:
                await member.add_roles(role)
                print("done")
            else:
                print("Member not found")
        else:
            print("Role not found")




@client.event
async def on_raw_reaction_remove(payload):
    pass

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question