Skip to content

Buttons

This Section will cover how to create a button, multiple buttons and also detect and handle button inputs.

Important

  • Each Button needs a Custom ID to detect when it was Pressed
  • You can get a Emoji on Windows using Win+.

Create One Button

This Construction will trigger when the !buttons Command was run, that will create and send the button with the Send Message(Components) Block.
Image

Create Multiple Buttons

We are going to use the same command like the first one and just add more Create Button Blocks. In Combination with Create Button Row
https://i.imgur.com/bOXExvC.png

Detect and handle a Button Press

You can use the Interaction Event to detect a Button Press using the Custom ID. Also to get the Current Time and Date you use the Create Date Block and using the Format Date Block you can get the Date in a Text Type.
To now send a message back to the User that used the Button, you can use the Reply to Interaction Block.

(Ephemeral means only visible to the user)

https://i.imgur.com/9imoEyd.png

Testing Everything

When you launch the bot you can now use the example command that was created, and with that the 3 Buttons should be sent. When you now click on a Button the message you reply!
Button Run

Edit a Button

You can also edit a Button, for example when you want to change the Label or the Style.

Example Button to edit

To edit a Button you need a button that you want to edit, for this we are going to use a slash command which is going to create the button and then reply it to the interaction.
Create Button for EDIT BUTTON EXAMPLE

Getting to the Edit Button

Now you have multiple ways how and when to edit the button, the simplest is to take the Interaction Event Block and then use Get Message Buttons Block to get the Buttons from the Message and then use the Edit Button Row Block to edit the Button of the Message. At the end use the Interaction Update Block to update the Interaction with the New Button and a New Text/Embed. Edit Button

How it looks in Discord

Edit Button in Discord

Still Issues or Questions?

If you have Issues or any questions you can always ask on the Discord Bot Builder Discord, or send me a DM: xcrafttm!