如何向发送类似 !color common
之类消息的成员添加角色
我在网上搜索并找到了这样的解决方案:
import discord
from discord.utils import get
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content == '!color common':
role = get(message.guild.roles, name='common')
await message.author.add_roles(role)
但是,它返回 discord.errors.Forbidden: 403 Forbidden (error code: 50013): Missing Permissions
。但是我已经允许它成为管理员。我怎样才能解决这个问题?谢谢!
这里是完整的错误信息:
Ignoring exception in on_message
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "main.py", line 314, in on_message
await message.author.add_roles(role)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/member.py", line 676, in add_roles
await req(guild_id, user_id, role.id, reason=reason)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/http.py", line 241, in request
raise Forbidden(r, data)
discord.errors.Forbidden: 403 Forbidden (error code: 50013): Missing Permissions