The problem is that my bot has administrator permissions and I don’t see how or why I am getting permission errors. This error pops up when the bot should be giving a role to a joining member.
@bot.event
async def on_member_join(member):
welcome_channel = discord.utils.get(member.guild.text_channels, name='welcome_channel')
guild=member.guild
if guild.member_count % 10 ==1: #to find the last digit of the member count to see if st or nd or rd or th should be placed at the end
embed=discord.Embed()
embed2=discord.Embed()
name=(member)
embed.set_author(name=f"{random.choice(greetings)} {name}. You are the {guild.member_count}st member", icon_url=member.avatar_url)
await welcome_channel.send(embed=embed)
embed2.set_thumbnail(url=member.avatar_url)
await welcome_channel.send(f"{random.choice(greetings)} {member.mention}. You are the {guild.member_count}st member", embed=embed2)
The exact errors that I get are:
Traceback (most recent call last):
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "c:\Users\Lenovo\Desktop\Python\VSC\Discord Bot\Main backup.py", line 53, in on_message
await message.author.add_roles(role)
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\member.py", line 777, in add_roles
await req(guild_id, user_id, role.id, reason=reason)
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\http.py", line 248, in request
raise Forbidden(r, data)
discord.errors.Forbidden: 403 Forbidden (error code: 50013): Missing Permissions
>Solution :
As said in Traceback, the error probably doesn’t come from on_member_join(), but from the on_message() event
You should check the order of the roles of your server. If bot’s role is below the role you want to give to a user, then you bot doesn’t have the permission to do so (as explained here)
Example :
