Skip to content

Pycord button callback #1943

Closed Answered by OmLanke
BatteTarte asked this question in Q&A
Discussion options

You must be logged in to vote

For programatically adding buttons, you should subclass discord.ui.Button. For eg-

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.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Lulalaby
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants