python - Discordpy2按钮interaction.edit_original_response()返回404未找到(错误代码:10015)

标签 python python-3.x discord.py discord-buttons

我正在尝试使用斜线命令中的按钮在 Discord.py 机器人中创建菜单。

我的代码:


    class helpbclass(discord.ui.View):

      def __init__(self):
        super().__init__()
        self.value = None

      @discord.ui.button(label="General",
                         style=discord.ButtonStyle.blurple,
                         emoji="📜")
      async def general(self, interaction: discord.Interaction,
                        button: discord.ui.Button):
                        await interaction.response.edit_original_response('general')

      @discord.ui.button(label="Moderation",
                         style=discord.ButtonStyle.blurple,
                         emoji="📜")
      async def moderation(self, interaction: discord.Interaction,
                           button: discord.ui.Button):
                        await interaction.edit_original_response(content='moderation')

      @discord.ui.button(label="QUIT", style=discord.ButtonStyle.red, emoji="📜")
      async def quit(self, interaction: discord.Interaction,
                     button: discord.ui.Button):
                        await interaction.edit_original_response(content='quit')
                        self.value = False
                        self.stop()


    @client.tree.command(name="test",
                         description="Menu testing",
                         guild=discord.Object(id=123456789))
    async def test(interaction: discord.Interaction):
      await interaction.response.defer()
      #code for embed
      view = helpbclass()
      await interaction.followup.send(embed=embed, view=view)
      # i also tried interaction.response.send_message, without the response.defer() at top

问题 它返回以下错误:

Traceback (most recent call last):
  File "/home/runner/AtlaReboot/venv/lib/python3.10/site-packages/discord/ui/view.py", line 425, in _scheduled_task
    await item.callback(interaction)
  File "main.py", line 61, in moderation
    await interaction.edit_original_response(content='moderation')
  File "/home/runner/AtlaReboot/venv/lib/python3.10/site-packages/discord/interactions.py", line 462, in edit_original_response
    data = await adapter.edit_original_interaction_response(
  File "/home/runner/AtlaReboot/venv/lib/python3.10/site-packages/discord/webhook/async_.py", line 218, in request
    raise NotFound(response, data)
discord.errors.NotFound: 404 Not Found (error code: 10015): Unknown Webhook

我的问题: 我检查了错误代码的含义,为什么会返回 webhook 错误? 如何在按下按钮时获取在命令输出中发送的原始嵌入,以便用另一个嵌入进行编辑?

最佳答案

我对您正在使用的不和谐包装器非常不熟悉,因为它的回调参数顺序相当奇怪。我通常会看到按钮出现在交互参数之前,但无论如何,请尝试在每个回调中执行 edit_original_message 之前推迟交互。

关于python - Discordpy2按钮interaction.edit_original_response()返回404未找到(错误代码:10015),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75123853/

相关文章:

python - numpy 排列 : how to make "precise" array of floats?

python - 为什么 cookielib.LWPCookieJar 接受空参数列表?

python - 如何获取对discord.py中的消息使用react的成员列表?

python - discord.py 为什么 @client.command 不起作用?

python - 在 Django 中查找模型字段的类型

python - MPI - 发送和接收矩阵列

python - Tkinter plt.figure() 不绘图,但Figure() 绘图

python - findall 错误 - NoneType' 对象没有属性 'findall'

python - Django+MySQL - "Authentication plugin ' caching_sha2_password'无法加载”

discord - 如何限制某个角色使用命令(discord.py)