Discord Bot Studio
  • Discord Bot Studio Documentation v2.0
  • Setting Up DBS
    • Create and Setup Bot With DBS [video]
    • Getting Started with DBS [text]
    • Inviting a Discord Bot to Your Server
    • Enabling Intents
    • Finding Your Bot Token
    • Using the Bot Editor
  • Response Nodes (by type)
    • Message Category
      • Send Message
      • Send Image
      • Send Embed
      • Delete Message
      • Check if Message is in Channel
    • Reaction Category
      • Add Reaction Listener
    • Variable Category
      • Store Value in Variable
      • Edit Variable
      • Check Variable Value
      • Check if Variable Exists
      • Generate Random Number
      • Get Mentioned User
    • User Data Category
      • Set User Data
      • Get User Data
      • Edit User Data
      • Check User Data
    • User Action Category
      • Add Role to User
      • Remove Role from User
    • Control Category
      • Wait
      • Switch Case
      • Multiple Input
    • Interaction Category
      • Reply To Interaction With Message
      • Get Interaction Option
      • Delete Interaction Reply
    • External Category
      • Call API
  • Running/Hosting Your Bot
    • Hosting your bot 24/7
    • Running Bot Locally
    • Multiple Bots
  • Commands
    • Message Commands
    • Kick / Ban Command
    • Purge Command
    • Role reaction menu
    • XP System
    • Ticket System
    • Command Aliases
  • Events
    • Overview
    • Event Types
      • User Joins Server
      • Any Message
      • Bot Initialization
      • Channel Create
      • Channel Delete
      • Channel Update
  • Misc
    • How to use custom emojis
    • Buttons and Selects
      • Determining which button was clicked
    • Slash Commands
    • Tagging a role
    • Tagging a channel
  • Mods
    • Creating Mods
    • Installing Mods
  • Spreadsheets
    • Using Spreadsheet Data
Powered by GitBook
On this page
  • How buttons work
  • Figuring out which button was clicked
  • Custom ID
  • Check the ID

Was this helpful?

  1. Misc
  2. Buttons and Selects

Determining which button was clicked

This tutorial will explain how you can determine which button was clicked by a user. This is useful if your bot has more than one button, and you want to be able to link specific functionality to each

PreviousButtons and SelectsNextSlash Commands

Last updated 3 years ago

Was this helpful?

How buttons work

It's possible to have multiple buttons per row, and multiple rows per message. The rule is that there can be one select, or five buttons per row, and up to five rows per message. This is covered in the video here:

Figuring out which button was clicked

The basic timeline for when a button is clicked is as follows:

  1. The button is added to the message when the bot creates the message

  2. A user sees the message and potentially clicks one or more buttons

  3. The ButtonInteraction event is fired

  4. Any responses you have connected to the event node will be executed

Custom ID

When you add a button to a message you will be asked to enter a Custom ID. This ID is how we will determine which button was clicked. For this reason, the Custom ID should be unique for each button. Make a note of what the custom ID is for each button you have, as we'll need it later.

Check the ID

To determine which button was clicked we will use a Switch Case node. This node lets us check the value of a variable against multiple values. We'll connect it to the Button Interaction event so we can check the value of the customId field of the interaction event.

We can double click on the switch case node to open it. In this case we are checking the value of the buttoninteraction.customId to see which button was clicked.

In this example I am checking for two possible values- custom_id_1 and custom_id_btn2. This correlates to two buttons I have with those as their custom IDs. If the button which I set the custom ID to custom_id_btn2 is clicked then the responses connected to that output will be executed.

It's possible to have an unlimited number of buttons and have the switch case node check for an unlimited number of values. Any responses can be connected to each output, allowing you to

Buttons and Selects