英文:
"discord.errors.Forbidden: 403 Forbidden (error code: 50013): Missing Permissions" when trying to send a message with embed
问题
Discord.py版本: 2.3.0
我尝试发送了一个带有嵌入的消息。没有嵌入的话一切都正常,但是使用嵌入时在我的日志中出现了"403 禁止访问"错误。
到目前为止,我在app_commands中实现了嵌入,并且它们正常工作,但是在聊天命令中出现了"403 禁止访问"错误。"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)
该命令在类别内部实现如下:
@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)
...
discord.errors.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'])])
- 发送更简单的嵌入,如下:
await ctx.send(content="a", embed=discord.Embed(title='Test', description="ddsdf"))
它有效了,但它只发送带有内容"a"的消息,没有嵌入。但日志中没有输出任何错误。
-
尝试删除"inline"字段
-
尝试阅读文档和在Google中搜索。没有帮助。文档示例也没有帮助。
请指导我正确的方向。谢谢!
英文:
Discord.py version: 2.3.0
I've tried to send a message with embed. Without embed it works just fine, but with it "403 forbidden" error shows up in my log.
So far I've implemented embeds in app_commands and they worked normally, but in chat commands the "403 forbidden" occurs. "intents.message_content" is set to True.
Embed is defined in class "CountryEmbed" like this:
<!-- language: python -->
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)
The command is implemented like this (inside cog):
@commands.command(name='countries')
async def countries(self, ctx: commands.Context, arg: str) -> None:
...
Full traceback:
<!-- language: python -->
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
I've tried:
- Change "embed" to "embeds" in ctx.send:
From:
<!-- language: python -->
await ctx.send(embed=CountryEmbed(name=data['name'], capital=data['capital'], population=data['population'], area=data['area'])
To:
<!-- language: python -->
await ctx.send(embeds=[CountryEmbed(name=data['name'], capital=data['capital'], population=data['population'], area=data['area'])])
- Send more simple embed like this:
<!-- language: python -->
await ctx.send(content="a", embed=discord.Embed(title='Test', description="ddsdf"))
It worked, but it only sends message with content "a" without embed. It doesn't output any error in the log, though.
-
Tried to remove "inline" fields
-
Tried to read the docs and search in Google. Nothing helped. Documentation examples didn't help, either.
Please, point me in the right direction. Thank you!
答案1
得分: 0
我解决了这个问题。您需要检查您服务器上的机器人角色权限。对于嵌入,它应该具有以下权限:
- 发送消息
- 嵌入链接
- 附加文件
此外,您可以有一些角色覆盖。您可能想使用类似 https://github.com/Gorialis/jishaku 的工具来精确定位角色覆盖。就是这样。干杯!
英文:
I solved the problem. You need to check bot role permissions on your server. For embeds it should have:
- send messages
- embed links
- attach files
Also you can have some role overrides. You may want to use something like https://github.com/Gorialis/jishaku to pinpoint role overrides. So that's all. Cheers!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论