ButtonBuilder class
constructor
The constructor provides one optional argument which is an object which provides the data for the ButtonBuilder class.
The object may contain the following information:
custom_id
: An id so you can recognize the button when it's being pressed by a member. The id must be unique and a string between 1-100 characters.style
: A number which defines which kind of style the button should have.label
: The text which should be on the button. The string must be between 1-100 characters.emoji
: An object which defines the emoji which should be on the button, if you want an emoji on the button. The object should provide whether the emoji is animated or not, the id of the emoji and the name of the emoji.disabled
: A boolean which defines whether the button can be pressed or not.url
: A url for the member to go to when the member presses the button.type
: A number which defines the type of component of the button. (2
means it's a button)
Properties
data
An object which makes it a valid object for the Discord API.
Functions
setCustomId
Sets a custom id for the button which will be returned to the bot once the button is pressed and makes you able to recognize the button. The function returns the same ButtonBuilder class so you don't have to declare it everytime again.
customId
A string of max 100 characters which will be returned to the bot in the buttonClick event so you can recognize the button which was pressed by the member.
setDisabled
Defines whether the button may be pressed by a member or not. The function returns the same ButtonBuilder class so you don't have to declare it everytime again.
disabled
A boolean which defines whether the button should be disabled or may be pressed by a member.
setLabel
Sets a label for the button which is visible to server members. The function returns the same ButtonBuilder class so you don't have to declare it everytime again.
label
A string of max 100 characters which should be the text on the button.
setText
Identical to the setLabel function. Sets a label for the button which is visible to server members. The function returns the same ButtonBuilder class so you don't have to declare it everytime again.
text
A string of max 100 characters which should be the text on the button.
setStyle
Sets the style for the button and defines how the button will look like. The function returns the same ButtonBuilder class so you don't have to declare it everytime again.
style
A string or a number which defines the style of the button. In the table below is explained which strings and numbers are allowed.
Blurple button
For a blurple button you can use the strings blurple
and primary
. You can also use the number 1
to define the blurple color.
Gray button
For a gray button you can use the strings gray
, grey
and secondary
. You can also use the number 2
to define the gray color.
Green button
For a green button you can use the strings green
and success
. You can also use the number 3
to define the green color.
Red button
For a red button you can use the strings red
and danger
. You can also use the number 4
to define the red button.
setURL
Sets a url for the button so when a member presses the button, the member will be redirected to the website. When setting the url, the style type will automatically change to a url button style. The function returns the same ButtonBuilder class so you don't have to declare it everytime again.
url
The url of the website the member should be redirected to when pressing the button. The url must be a valid website url.
setEmoji
Adds an emoji to the button. The emoji must be a unicode emoji or an instance of the Emoji class. The function returns the same ButtonBuilder class so you don't have to declare it everytime again.
emoji
The emoji which should be added to the button. The emoji must be a unicode emoji or an instance of the Emoji class.
toJSON
Converts the ButtonBuilder class to an object to make it a valid object for the Discord API. The function returns the same data as the data property.
Last updated