0

I have made a meme command which looks like this

Is there any way to end the interaction on clicking the End Interaction button. Please help me with the end_interaction function.

Code:

@commands.command(aliases=['m'], description='Posts memes from r/memes')
    async def meme(self, ctx):
        submissions = await get_memes('memes')
        button1 = Button(label='Next Meme', style=discord.ButtonStyle.green)
        button2 = Button(label='End Interaction', style=discord.ButtonStyle.red)

        async def next_meme(interaction):
            if len(submissions) == 0:
                await interaction.response.edit_message(content='No more memes available')
                return
            submissions.pop(0)
            embed.title = submissions[0].title
            embed.url = submissions[0].url
            embed.set_image(url=submissions[0].url)
            await interaction.response.edit_message(embed=embed)

        async def end_interaction(interaction):
            pass
            # I have no idea what to do here

        view = View()
        view.add_item(button1)
        view.add_item(button2)
        embed = discord.Embed(title=submissions[0].title, url=submissions[0].url, colour=discord.Colour.random())
        embed.set_image(url=submissions[0].url)
        await ctx.send(embed=embed, view=view)
        button1.callback = next_meme
        button2.callback = end_interaction
Sandy
  • 247
  • 3
  • 12

1 Answers1

0

If I understand what you're trying to do properly, can't you try to change the button1 & button2 callback to None? (or any other way to kind of "unbind" the button to the functions).

EDIT: Seems there is a disabled bool on the buttons, you can try something like

async def end_interaction(interaction):
    button1.disabled = True
    button2.disabled = True

Source of the edit info: https://stackoverflow.com/a/71013761/18312347

Luka Cerrutti
  • 667
  • 1
  • 4
  • 9