行为不正常的Discord.py Bot具有权限

时间:2020-03-25 22:24:38

标签: python bots discord discord.py

因此,我正在研究Discord Bot,并尝试进行角色分配。我确保使用的是新的重写系统,并确保给了bot管理权限。我几乎采取了我能想到的所有措施,但它根本没有用。我看了更新的API来处理它,使用示例代码作为框架,这是代码

import os

import discord
from discord.utils import get as dget
from discord.ext.commands import Bot
from dotenv import load_dotenv

load_dotenv('key.env')
TOKEN = os.getenv('DISCORD_TOKEN')

client = Bot(command_prefix = '!')

@client.event
async def on_ready():
    print('Connected')

@client.command()
async def role(ctx):
    user = ctx.message.author
    role = discord.utils.get(ctx.guild.roles, name="Sample")
    await user.add_roles(role)

client.run(TOKEN)

这是我得到的错误:

Ignoring exception in command role:
Traceback (most recent call last):
  File "C:\Users\chris\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 83, in wrapped
    ret = await coro(*args, **kwargs)
  File "d:/Google Drive/Coding/Khasbot/main.py", line 22, in role
    await user.add_roles(role)
  File "C:\Users\chris\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\member.py", line 641, in add_roles        
    await req(guild_id, user_id, role.id, reason=reason)
  File "C:\Users\chris\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\http.py", line 221, in request
    raise Forbidden(r, data)
discord.errors.Forbidden: 403 Forbidden (error code: 50013): Missing Permissions

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\chris\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\bot.py", line 892, in invoke 
    await ctx.command.invoke(ctx)
  File "C:\Users\chris\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 797, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "C:\Users\chris\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 92, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: Forbidden: 403 Forbidden (error code: 50013): Missing Permissions

老实说,我不知道出什么问题了。我已经尝试了无尽的尝试,甚至完全创建了一个全新的机器人。还是一样的问题。昨晚它起作用了,实际上根本不会这样做。

1 个答案:

答案 0 :(得分:0)

确保您的漫游器必须在您的服务器上具有“管理角色”权限,并且添加角色必须的角色必须低于您的漫游器最高角色。 让您完成这两件事。