403 Forbidden (error code: 50001): Missing Access when adding role | discord.py(403 Forbidden(错误代码:50001):添加角色时缺少访问权限 |不和谐.py)
问题描述
我正在尝试快速为人们分配不同的角色,以给用户一种他们的名字是彩虹的印象(是的,我知道它反对 TOS),并且我开始在删除他们之前向人们添加角色.但是,在添加角色时,我在这篇文章的标题中得到了错误.我对此进行了调查并尝试了很多方法来解决它.机器人的角色比分配的角色更高.这是我的代码和输出:
I am trying to ass different roles to people rapidly to give users the impression of their name being rainbow ( yes I know its against TOS ), and I am starting by adding roles to people before I remove them. However, when adding roles I get the error in the title of this post. I have looked into this and tried quite a few ways to fix it. The bot has a higher role than the roles being give out. Here is my code and the output:
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:UsersUserAppDataLocalProgramsPythonPython38-32libsite-packagesdiscordclient.py", line 312, in _run_event
await coro(*args, **kwargs)
File "C:UsersUserDesktop est est.py", line 29, in on_ready
await user.add_roles(color)
File "C:UsersUserAppDataLocalProgramsPythonPython38-32libsite-packagesdiscordmember.py", line 641, in add_roles
await req(guild_id, user_id, role.id, reason=reason)
File "C:UsersUserAppDataLocalProgramsPythonPython38-32libsite-packagesdiscordhttp.py", line 241, in request
raise Forbidden(r, data)
discord.errors.Forbidden: 403 Forbidden (error code: 50001): Missing Access
推荐答案
确保您拥有授予机器人的角色,该角色可以访问 managing roles.此外,当您从开发门户添加机器人时,您可以为其授予权限.
Make sure you have a role given to the bot which has access to managing roles. Also when you add the bot from the dev portal you can give it permissions.
最佳做法是创建一个名为 BOT 的角色,并拥有所有权限并将其提供给您在服务器中拥有的所有机器人
Best practice is to make a role called BOT with all the permissions and give it to all the bots you have in the server
这篇关于403 Forbidden(错误代码:50001):添加角色时缺少访问权限 |不和谐.py的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:403 Forbidden(错误代码:50001):添加角色时缺少访问权限 |不和谐.py
- ";find_element_by_name(';name';)";和&QOOT;FIND_ELEMENT(BY NAME,';NAME';)";之间有什么区别? 2022-01-01
- 使用公司代理使Python3.x Slack(松弛客户端) 2022-01-01
- 如何使用PYSPARK从Spark获得批次行 2022-01-01
- 我如何卸载 PyTorch? 2022-01-01
- YouTube API v3 返回截断的观看记录 2022-01-01
- 我如何透明地重定向一个Python导入? 2022-01-01
- 计算测试数量的Python单元测试 2022-01-01
- 检查具有纬度和经度的地理点是否在 shapefile 中 2022-01-01
- CTR 中的 AES 如何用于 Python 和 PyCrypto? 2022-01-01
- 使用 Cython 将 Python 链接到共享库 2022-01-01
