Can't edit an embed on callback function

42 Views Asked by At

I am having troubles with editing a message with an embed. I want to replace the embed with another embed that is being created in a callback function button click (which executes on the button click). On the screenshots below you can see my problem. When I execute /test command, bot sends the first embed with a button. When I click a button, instead of another embed, bot sends <discord.embeds.Embed object at 0x7499da9001f0>, and the first embed is still visible.

enter image description here

enter image description here

The code is pasted below. I am using cogs,

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))

I am using py-cord==2.4.1

1

There are 1 best solutions below

0
syrok On

turns out I need to change

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

to

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