Discord PY On member 加入添加角色

Discord PY On member Join add Roles

我对 Discord PY 有点陌生,我正在寻找一种方法来添加角色,如果有人 DM 是机器人的密钥。 我研究并输入了这段代码,但遇到错误请帮忙 密码是

Mod = 789737793042776074


@Client.event
async def on_member_join(person):
    async for guild in Client.fetch_guilds(limit=150):
        channel = person
        await channel.send(f"Thanks for Joining {guild.name}")
        reply = await Client.wait_for('message', timeout=60)
        if reply.content == 'STron':
#         role = get(guild.roles, id = Mod)
          await channel.send('Sshh I Gave you Moderator')
          await person.add_roles(id = Mod)

我收到一个错误

Ignoring exception in on_member_join
Traceback (most recent call last):
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 333, in _run_event
    await coro(*args, **kwargs)
  File "main.py", line 28, in on_member_join
    await person.add_roles(id = Mod)
TypeError: add_roles() got an unexpected keyword argument 'id'

您需要获取角色然后添加

Mod = 789737793042776074

@Client.event
async def on_member_join(person):
    await person.send(f"Thanks for Joining {person.guild.name}")
    msg = await Client.wait_for("message", check=lambda m: not m.guild and m.author.id == person.id)
    if msg.content == "STron":
        await person.send("Sshh I gave you Moderator")
        await person.add_roles(person.guild.get_role(Mod))
@client.event
async def on_member_join(user):
    await user.send(f"Message and variables")
    await user.add_roles(id) ##or await user.add_roles(ctx.guild.get_role(Name or Id))
async def on_member_join(member): 
  role = discord.utils.get(member.guild.roles, name="Role name here")
  await member.add_roles(role)

这应该有所帮助。尝试阅读文档或研究 discord.utils.get