#Discord python Buttons
62 messages · Page 1 of 1 (latest)
Pycord?
Learn all about implementing buttons in your Discord Bot using Pycord.
Oh
await interaction_check(interaction)
The library has helpers to help create component-based UIs. Shortcut decorators: Objects: Attributes children, disable_on_timeout, message, timeout. Methods cls View.from_message, def add_item, def...
discord.ui.View.interaction_check()
And then is_component() to check that the interaction comes from the button
Oh yeesh
There's like 10 ways of doing that, lmao
Yes! It works sort of, it does detect it when I click the button however I get this error:
interaction.response.send_message("pressed")
AttributeError: 'Button' object has no attribute 'response'```
Hmm
Hold on
There's the await callback(interaction) that's for discord.ui.Button
Which is what you use in the add_item
Hmmm
The library has helpers to help create component-based UIs. Shortcut decorators: Objects: Attributes children, disable_on_timeout, message, timeout. Methods cls View.from_message, def add_item, def...
OH
view = discord.ui.View()
customButton = discord.ui.Button(label="Test Button", style=discord.ButtonStyle.green)
async def customButton_callback(interaction):
await interaction.response.send_message("Hello!")
customButton.callback = customButton_callback
view.add_item(customButton)
await client.get_channel(channelId).send(embed=embed, view=view)
Try that
I guess you could also use customButton.callback = await interaction.response.send_message("Hello!")
That works however it doesn't work anymore when retstarting the bot...
Hmmm
- how do I access the user who pressed the button with that?
Models are classes that are received from Discord and are not meant to be created by the user of the library. Attributes key, url. Methods def is_animated, async read, def replace, async save, def ...
And
view = discord.ui.View()
customButton = discord.ui.Button(label="Test Button", custom_id="testButton1" style=discord.ButtonStyle.green)
async def customButton_callback(interaction):
await interaction.response.send_message("Hello!")
view.timeout = None
customButton.callback = customButton_callback
view.add_item(customButton)
bot.add_view(view)
await client.get_channel(channelId).send(embed=embed, view=view)
I think?
Lemeee try
Or client.add_view() if you're using client instead of bot
In function
We somehow need to store the view and then use add_view in the on_read event I assume
Yeah
How can I make a json object from view tho
Ok, I got restarting to work
Now all I need is access the user who clicked the button 
interaction.user ?
What's the code?
@unborn mauve has been given 8 kudos from @stable nymph.
Hahah, I linked you the interaction docs a while ago
Here, hahah
You can see all the attributes it has got that you can use


