問(wèn)題描述
我正在嘗試快速為人們分配不同的角色,以給用戶一種他們的名字是彩虹的印象(是的,我知道它反對(duì) TOS),并且我開(kāi)始在刪除他們之前向人們添加角色.但是,在添加角色時(shí),我在這篇文章的標(biāo)題中得到了錯(cuò)誤.我對(duì)此進(jìn)行了調(diào)查并嘗試了很多方法來(lái)解決它.機(jī)器人的角色比分配的角色更高.這是我的代碼和輸出:
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
推薦答案
確保您擁有授予機(jī)器人的角色,該角色可以訪問(wèn) managing roles
.此外,當(dāng)您從開(kāi)發(fā)門戶添加機(jī)器人時(shí),您可以為其授予權(quán)限.
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.
最佳做法是創(chuàng)建一個(gè)名為 BOT
的角色,并擁有所有權(quán)限并將其提供給您在服務(wù)器中擁有的所有機(jī)器人
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
這篇關(guān)于403 Forbidden(錯(cuò)誤代碼:50001):添加角色時(shí)缺少訪問(wèn)權(quán)限 |不和諧.py的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!