Pycord button callback #1943
-
My button does not callback here is my code class MyView(discord.ui.View):
def __init__(self, label: str):
super().__init__()
button = discord.ui.Button(label=label, style=discord.ButtonStyle.primary, emoji="😎")
self.add_item(button)
async def button_callback(self, interaction):
await interaction.response.send_message("Hey")
@bot.slash_command()
async def test(ctx, word:str):
await ctx.respond("Take the view",view=MyView(word)) there is no error message but button callback dont work |
Beta Was this translation helpful? Give feedback.
Answered by
OmLanke
Feb 24, 2023
Replies: 1 comment
-
For programatically adding buttons, you should subclass class MyButton(discord.ui.Button):
async def callback(self, interaction: discord.Interaction):
...
# You can now either subclass `discord.ui.View`, work with instances, or just use the constructor.
@bot.slash_command()
async def my_cmd(ctx: discord.ApplicationContext, word:str):
await ctx.respond("Hello there", view=discord.ui.View(MyButton(label=word, ...))) It is recommended to ask questions in the discord server. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Lulalaby
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For programatically adding buttons, you should subclass
discord.ui.Button
. For eg-It is recommended to ask questions in the discord server.