无法编辑嵌入回调函数

问题描述 投票:0回答:1

我在编辑嵌入消息时遇到问题。我想将嵌入替换为在回调函数button click(在按钮单击时执行)中创建的另一个嵌入。 在下面的屏幕截图中您可以看到我的问题。当我执行 /test 命令时,机器人会使用按钮发送第一个嵌入。当我单击按钮时,机器人发送 ,而不是另一个嵌入,并且第一个嵌入仍然可见。

代码粘贴在下面。我正在使用齿轮,

from discord.ui import Button, View
import discord
from discord.ext import commands


class TestCog(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    @commands.slash_command(name='test', description='')
    async def flip(self, ctx):

        async def button_callback(interaction):
                embed = discord.Embed(
                description=f"{ctx.author.mention}\nNew embed!! Which I can't see",
                color=0xf3c70d,
                )
                await interaction.response.edit_message(content=embed, view=None)


        button = Button(custom_id='button', label='click me', style=discord.ButtonStyle.green, emoji="🪙")
        button.callback = button_callback
        my_view = View()
        my_view.add_item(button)

        embed = discord.Embed(
        title="First embed. This one I can see clearly.",
        color=0xf3c70d,
        )

        await ctx.respond(embed=embed, view=my_view)

def setup(bot):
    bot.add_cog(TestCog(bot))

我正在使用 py-cord==2.4.1

python discord discord.py pycord
1个回答
0
投票

原来我需要改变

await interaction.response.edit_message(content=embed, view=None)

await interaction.response.edit_message(embed=embed, view=None)
© www.soinside.com 2019 - 2024. All rights reserved.