向用户discord.py添加角色

时间:2020-10-29 22:11:52

标签: python

我想在一个人加入我的不和谐时添加一个角色,所以我不知道什么在这里不起作用。

@bot.event
async def on_member_join(member):
    pseudo = member.mention
    print(member)

    print("New member connected")
    # Envoyer un message privé au nouveau membre

    await member.send(f"Bienvenue sur CodeNet {pseudo} \n Fait la commande !!regles pour lire les règles ! \n Notre site web: http://codenet.ddns.net/")
    channel = bot.get_channel(771466599369539584)
    await channel.send(f"Bienvenue {pseudo} sur CodeNet !!!")
    test = discord.utils.get(member.guild.roles, name="membre")
    await member.add_roles(member, test) 

这是错误

Ignoring exception in on_member_join
Traceback (most recent call last):
  File "C:\Users\Mick\AppData\Roaming\Python\Python37\site-packages\discord\client.py", line 333, in _run_event
    await coro(*args, **kwargs)
  File "C:/Users/Mick/PycharmProjects/lexigreybot/main.py", line 31, in on_member_join
    await member.add_roles(member, test)
  File "C:\Users\Mick\AppData\Roaming\Python\Python37\site-packages\discord\member.py", line 664, in add_roles
    await req(guild_id, user_id, role.id, reason=reason)
  File "C:\Users\Mick\AppData\Roaming\Python\Python37\site-packages\discord\http.py", line 243, in request
    raise NotFound(r, data)
discord.errors.NotFound: 404 Not Found (error code: 10011): Unknown Role

0 个答案:

没有答案