我在编辑嵌入消息时遇到问题。我想将嵌入替换为在回调函数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
原来我需要改变
await interaction.response.edit_message(content=embed, view=None)
到
await interaction.response.edit_message(embed=embed, view=None)