Pycord button view #1938
-
Hello is there any way to import command arg to button view? here is my code class MyView(discord.ui.View):
@discord.ui.button(label=word, style=discord.ButtonStyle.success)#button label with the word command arg
async def button_callback(self, button, interaction):
await interaction.response.send_message(f"You clicked the button!")
@bot.slash_command()
async def test(ctx, word:str):
await ctx.respond("Take the view",view=myview()) i want to show to word arg on the button label Is this possible? |
Beta Was this translation helpful? Give feedback.
Answered by
JustaSqu1d
Feb 23, 2023
Replies: 1 comment 1 reply
-
You can pass in the arguments into the view constructor and create the button by object: class MyView(discord.ui.View):
def __init__(self, label: str):
super().__init__()
button = discord.ui.Button(label = label,
...)
async def button_callback(self, interaction):
...
@bot.slash_command()
async def test(ctx, word:str):
await ctx.respond("Take the view",view=MyView(word)) I would like to add that this discussion category should not be used for help, rather, please join our Discord server for help instead. If you require further assistance please do the same. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
BatteTarte
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can pass in the arguments into the view constructor and create the button by object:
I would like to add that this discussion category should not be used for help, rather, please join our Discord server for help instead. If you require further assistance please do the same.