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
基础教程推荐
- 在 Django Admin 中使用内联 OneToOneField 2022-01-01
- Python,确定字符串是否应转换为 Int 或 Float 2022-01-01
- 比较两个文本文件以找出差异并将它们输出到新的文本文件 2022-01-01
- Kivy 使用 opencv.调整图像大小 2022-01-01
- 究竟什么是“容器"?在蟒蛇?(以及所有的 python 容器类型是什么?) 2022-01-01
- kivy 应用程序中的一个简单网页作为小部件 2022-01-01
- Python 中是否有任何支持将长字符串转储为块文字或折叠块的 yaml 库? 2022-01-01
- 在 Python 中将货币解析为数字 2022-01-01
- 对多索引数据帧的列进行排序 2022-01-01
- matplotlib 设置 yaxis 标签大小 2022-01-01
