Discord.py 2.3.0聊天命令发送Embed报403权限缺失错误求助
Discord.py 2.3.0聊天命令发送Embed时出现403 Forbidden错误
环境
Discord.py version: 2.3.0
问题详情
- 发送不带Embed的消息一切正常,但发送包含Embed的消息时日志出现
403 forbidden错误 - app_commands中实现的Embed可以正常工作,但聊天命令(chat commands)中触发该错误,且已将
intents.message_content设置为True
相关代码
CountryEmbed类定义
class CountryEmbed(discord.Embed): def __init__(self, name: str, capital: str, population: int, area: float): super().__init__( title="Country info", colour=discord.Colour.from_str("#a23331"), type='rich', ) self.add_field(name='Name', value=name, inline=True) self.add_field(name='Capital', value=capital, inline=True) self.add_field(name='Population', value=str(population), inline=True) self.add_field(name='Area', value=f"{area} m²", inline=True)
聊天命令实现(cog中)
@commands.command(name='countries') async def countries(self, ctx: commands.Context, arg: str) -> None: ...
完整错误回溯
Traceback (most recent call last): File "D:\Documents\Projects\Python\Bot\venv\Lib\site-packages\discord\ext\commands\core.py", line 235, in wrapped ret = await coro(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Documents\Projects\Python\Bot\cogs\webscrap.py", line 31, in countries await ctx.send(embed=CountryEmbed(name=data['name'], capital=data['capital'], population=data['population'], area=data['area'])) File "D:\Documents\Projects\Python\Bot\venv\Lib\site-packages\discord\ext\commands\context.py", line 1024, in send return await super().send( ^^^^^^^^^^^^^^^^^^^ File "D:\Documents\Projects\Python\Bot\venv\Lib\site-packages\discord\abc.py", line 1562, in send data = await state.http.send_message(channel.id, params=params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Documents\Projects\Python\Bot\venv\Lib\site-packages\discord\http.py", line 739, in request raise Forbidden(response, data) discord.errors.Forbidden: 403 Forbidden (error code: 50013): Missing Permissions The above exception was the direct cause of the following exception: Traceback (most recent call last): File "D:\Documents\Projects\Python\Bot\venv\Lib\site-packages\discord\ext\commands\bot.py", line 1350, in invoke await ctx.command.invoke(ctx) File "D:\Documents\Projects\Python\Bot\venv\Lib\site-packages\discord\ext\commands\core.py", line 1029, in invoke await injected(*ctx.args, **ctx.kwargs) # type: ignore ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Documents\Projects\Python\Bot\venv\Lib\site-packages\discord\ext\commands\core.py", line 244, in wrapped raise CommandInvokeError(exc) from exc discord.ext.commands.errors.CommandInvokeError: Command raised an exception: Forbidden: 403 Forbidden (error code: 50013): Missing Permissions
已尝试的解决方法
- 将
ctx.send中的embed参数改为embeds:
修改前:
修改后:await ctx.send(embed=CountryEmbed(name=data['name'], capital=data['capital'], population=data['population'], area=data['area'])await ctx.send(embeds=[CountryEmbed(name=data['name'], capital=data['capital'], population=data['population'], area=data['area'])]) - 发送简化版Embed:
仅发送了内容"a",未附带Embed,且日志无错误信息await ctx.send(content="a", embed=discord.Embed(title='Test', description="ddsdf")) - 移除Embed中的
inline字段 - 查阅官方文档及相关资料,但未找到有效解决方法
请求帮助
恳请指明解决方向,感谢!
内容的提问来源于stack exchange,提问作者Hakito82
相关产品推荐
相关产品推荐

