我正在尝试快速地给人们分配不同的角色,以给用户留下他们的名字是Rainbow的印象(是的,我知道它是反对TOS的),并且我在删除角色之前先向他们添加角色。但是,添加角色时,我在此标题中看到了错误。我已经研究了这个问题,并尝试了多种修复方法。僵尸程序所扮演的角色要比被赋予的角色更高。这是我的代码和输出:
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix="$")
role_name = "Rainbow Six Seige"
peopleWithRole = []
guild = discord.Guild
@bot.event
async def on_ready():
print("Logged in as")
print(bot.user.name)
print("------")
guild = bot.guilds[0]
colours = [discord.utils.get(guild.roles, name='red'),
discord.utils.get(guild.roles, name='green'),
discord.utils.get(guild.roles, name='blue')
]
role = discord.utils.find(
lambda r: r.name == role_name, guild.roles)
for user in guild.members:
if role in user.roles:
peopleWithRole.append(user)
for color in colours:
for user in peopleWithRole:
await user.add_roles(color)
bot.run("my token")
输出:
Logged in as
test bot
------
Ignoring exception in on_ready
Traceback (most recent call last):
File "C:\Users\User\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\client.py", line 312, in _run_event
await coro(*args, **kwargs)
File "C:\Users\User\Desktop\test\test.py", line 29, in on_ready
await user.add_roles(color)
File "C:\Users\User\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\User\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\http.py", line 241, in request
raise Forbidden(r, data)
discord.errors.Forbidden: 403 Forbidden (error code: 50001): Missing Access
答案 0 :(得分:2)
确保您已赋予有权访问managing roles
的漫游器角色。另外,当您从开发人员门户网站添加漫游器时,您可以为其授予权限。
最佳做法是创建一个具有所有权限的名为BOT
的角色,并将其分配给您在服务器中拥有的所有漫游器