Issue
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")
output:
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
Solution
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 needed.
Best practice for verified bots is to make a role called BOT
with all the permissions and give it to all the bots you have in the server
Answered By - Abdulaziz
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.