'How to end an interaction in discord embed buttons (Python)
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
Solution 1:[1]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
