我制作了一个分配成员角色的不和谐机器人,但它不起作用

时间:2021-06-23 07:06:29

标签: discord.py

这是我的代码,我正在使用它

client = discord.Client()

@client.event
async def on_ready():
    print('We have logged in as {0.user}'.format(client))

@client.event
async def on_message(message):
    if message.author == client.user:
      return
    member = message.author

    
    role = discord.utils.find(lambda r: r.name == 'Member', message.guild.roles)
    if role in member.roles :
      await message.channel.send(message.author.mention + " please move this conversation to #unverified-chat")

    else:
      var = discord.utils.get(message.guild.roles, name="Member")
      if member is not None :
        await member.add_roles(var)
        await message.channel.send('Hello ' + message.author.mention + '! You have been granted the role of a member')

keep_alive()
client.run(token)

即使我已授予机器人管理员权限,我也会出错:-

Traceback (most recent call last):
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 343, in _run_event
    await coro(*args, **kwargs)
  File "main.py", line 24, in on_message
    await member.add_roles(var)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/member.py", line 777, in add_roles
    await req(guild_id, user_id, role.id, reason=reason)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/http.py", line 248, in request
    raise Forbidden(r, data)
discord.errors.Forbidden: 403 Forbidden (error code: 50013): Missing Permissions

错误说我没有给机器人所需的权限,但我已经给了它所有的权限(包括管理员权限)。谁能给我解释一下?

0 个答案:

没有答案