Here's an example basic button:
button = Button(label="This is a button", style=discord.ButtonStyle.blurple)
async def button_callback(interaction):
await interaction.response.edit_message(embed=some_embed)
button.callback = button_callback
But a button like this can be used by anyone, which is not what I want. I know a method to allow only the command user to use button, which is this one:
button = Button(label="BACK", style=discord.ButtonStyle.blurple)
async def button_callback(interaction):
if interaction.user == ctx.author:
await interaction.response.edit_message(embed=some_embed)
else:
await ctx.send("that is not your button")
back_button.callback = button_callback
We use an if statement
to check if the button-clicker is the ctx.author
(or command user) but I do not want others to be able to click the button. I want the button to be disabled for other people. If you do not know a method to disable the button for other people, is there at least a better way to do this than just send "that is not your button"?
I am not sure if you are using a third party package to do this, but with the official discord.py 2.0 alpha version you can override the interaction check in the View class, like this:
For that, you should subclass the Button into its own View class, something like this will work:
https://discordpy.readthedocs.io/en/master/interactions/api.html?highlight=interaction%20check#discord.ui.View.interaction_check