D
D
doom252020-11-16 23:35:59
Python
doom25, 2020-11-16 23:35:59

Why is the role not automatically assigned?

Hello. I am not given a role on the server automatically. Cmd doesn't show any errors. Help me please.

PS Here is the code:
#Autorole

@Bot.event
async def on_member_join(member):
    if role := member.guild.get_role(769849037137641482):
        await member.add_roles(role)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
soremix, 2020-11-16
@SoreMix

Incorrect use :=
Use !=, respectively, the role will first need to be entered in the role variable

A
Apache, 2020-11-17
@igor_89squad

I also wrote a bot on the discord.

It's better to do that.
@bot.event # Когда человек заходит на канал бот приветствует его.
async def on_member_join(member):
    channel = bot.get_channel(id канала)
    await member.add_roles(discord.utils.get(member.guild.roles, id=роль))
    await channel.send(f'Добро пожаловать {member.name}!')

M
Maxim Nevzorov, 2020-11-17
@fixator10

Verify that a role with the specified ID exists. For example, manually mentioning the specified role by ID, sending a manual mention of the role: <@&769849037137641482>.
If the role exists, also make sure you have all the required intents. on_member_joinrequires Members intent: https://discordpy.readthedocs.io/en/stable/api.htm...
7Nmbvar.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question