0
votes

My code is:

@client.event
async def on_raw_reaction_add(payload):

    message_id = payload.message_id
    if message_id == 768549092674502666:
        if payload.emoji.name == 'white_check_mark':
            role = '<:Member:765291826151555104>'
            await member.add_role(role)

and i'm getting no results from the debugger or except when the bot adds a reaction or logs on which are other code completely inaccosiated with this part of the code.

1
Who is member?Guimoute
Member is the adder of the reaction, or so the docs sayYusuf Ziya
but if you're talking about the role, its just my role in my server that i've madeYusuf Ziya
Ok thanks. I was talking about the variable member not the role. Is it defined earlier in your code?Guimoute
no, none other place mentions it in my code, do i have to do payload.member or something?Yusuf Ziya

1 Answers

1
votes

In the new version of discord.py(1.5.x), there're some updates about Intents. Intents are like permissions and for using some of the events or getting members, channels etc. you need to define it before you define the client = discord.Bot(prefix='').

Then, you need to define the member to add role. You can simply do member = payload.member.

And also you need to get role with discord.utils.get(). You can't define a role with string.

import discord

intents = discord.Intents().all()
client = discord.Bot(prefix='', intents=intents)


@client.event
async def on_raw_reaction_add(payload):
    if payload.message_id == 768549092674502666 and payload.emoji.name == 'white_check_mark':
        guild = client.get_guild(guild id)
        role = discord.utils.get(guild.roles, name="role's name")
        await payload.member.add_roles(role)



If you want to get more information about Intents, you can check the API References