"discord.errors.Forbidden: 403 Forbidden (error code: 50013): Missing Permissions" when trying to send a message with embed

huangapple go评论76阅读模式
英文:

"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=&quot;Country info&quot;,
            colour=discord.Colour.from_str(&quot;#a23331&quot;),
            type=&#39;rich&#39;,
        )

        self.add_field(name=&#39;Name&#39;, value=name, inline=True)
        self.add_field(name=&#39;Capital&#39;, value=capital, inline=True)
        self.add_field(name=&#39;Population&#39;, value=str(population), inline=True)
        self.add_field(name=&#39;Area&#39;, value=f&quot;{area} m&#178;&quot;, inline=True)

The command is implemented like this (inside cog):

   @commands.command(name=&#39;countries&#39;)
    async def countries(self, ctx: commands.Context, arg: str) -&gt; None:
       ...

Full traceback:

<!-- language: python -->

Traceback (most recent call last):
  File &quot;D:\Documents\Projects\Python\Bot\venv\Lib\site-packages\discord\ext\commands\core.py&quot;, line 235, in wrapped
    ret = await coro(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File &quot;D:\Documents\Projects\Python\Bot\cogs\webscrap.py&quot;, line 31, in countries
    await ctx.send(embed=CountryEmbed(name=data[&#39;name&#39;], capital=data[&#39;capital&#39;], population=data[&#39;population&#39;], area=data[&#39;area&#39;]))
  File &quot;D:\Documents\Projects\Python\Bot\venv\Lib\site-packages\discord\ext\commands\context.py&quot;, line 1024, in send
    return await super().send(
           ^^^^^^^^^^^^^^^^^^^
  File &quot;D:\Documents\Projects\Python\Bot\venv\Lib\site-packages\discord\abc.py&quot;, line 1562, in send
    data = await state.http.send_message(channel.id, params=params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File &quot;D:\Documents\Projects\Python\Bot\venv\Lib\site-packages\discord\http.py&quot;, 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 &quot;D:\Documents\Projects\Python\Bot\venv\Lib\site-packages\discord\ext\commands\bot.py&quot;, line 1350, in invoke
    await ctx.command.invoke(ctx)
  File &quot;D:\Documents\Projects\Python\Bot\venv\Lib\site-packages\discord\ext\commands\core.py&quot;, line 1029, in invoke
    await injected(*ctx.args, **ctx.kwargs)  # type: ignore
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File &quot;D:\Documents\Projects\Python\Bot\venv\Lib\site-packages\discord\ext\commands\core.py&quot;, 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[&#39;name&#39;], capital=data[&#39;capital&#39;], population=data[&#39;population&#39;], area=data[&#39;area&#39;])

To:
<!-- language: python -->

await ctx.send(embeds=[CountryEmbed(name=data[&#39;name&#39;], capital=data[&#39;capital&#39;], population=data[&#39;population&#39;], area=data[&#39;area&#39;])])
  • Send more simple embed like this:
    <!-- language: python -->
await ctx.send(content=&quot;a&quot;, embed=discord.Embed(title=&#39;Test&#39;, description=&quot;ddsdf&quot;))

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!

huangapple
  • 本文由 发表于 2023年7月7日 03:31:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/76632027.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定