1const discord = require('discord.js'); //Define the discord.js module
2const client = new discord.Client(); //Creating discord.js client (constructor)
3require('discord-buttons')(client);
4const { MessageButton, MessageActionRow } = require('discord-buttons')
5
6
7client.on('message', async message => {
8 if(message.content === "test"){
9 const button = new MessageButton()
10 .setLabel("test")
11 .setStyle("green")
12 .setID("btn1")
13
14 message.channel.send("test components", button)
15 }
16})
17
18client.on('clickButton', async (button) => {
19 if(button.id === "btn1"){
20 await button.reply.defer()
21 await button.message.channel.send("button green")
22 }
23})
24
25
26client.login('Your Token')
27
1//Note that you need the Node module installed!
2let button = new disbut.MessageButton()
3 .setStyle('red') //default: blurple
4 .setLabel('My First Button!') //default: NO_LABEL_PROVIDED
5 .setID('click_to_function') //note: if you use the style "url" you must provide url using .setURL('https://example.com')
6 .setDisabled(); //disables the button | default: false
7
8message.channel.send('Hey, i am powered by https://npmjs.com/discord-buttons', button);
1/*Sending multiple embeds and buttons
2Assuming you have them created.
3*/
4
5message.channel.send('Optional Normal Text', {
6 buttons: [button1, button2],
7 embeds: [embed1, embed2]
8})
9
10// You can do the same for sending only 1 button or embed
11
12message.channel.send('option blahblah', {
13 button: button1,
14 embed: embed1
15})
16
17//Just some alternative ways to do this :)
1const disbut = require('discord-buttons')(client); // you'll need this module along side discord.js
2let YESbutton = new disbut.MessageButton() // button yes
3.setStyle('green') // green color
4// if .setStyle('url'), then .setURL('https://discord-buttons.js.org/')
5.setLabel('yea') // yea text
6.setID('yes') // button id. if style is url, ignore this, url buttons dont have id's
7let nobutton = new disbut.MessageButton() // button no
8.setStyle('red') // red color, there also exists blurple and gray
9.setLabel('nah') // nah text
10.setID('no') // button id
11.setDisabled() // OPTIONAL
12
13message.channel.send('did you guys subscribe to technoblade?', {
14 buttons: [YESbutton, nobutton]
15})
16
17client.on('clickButton', async (button) => {
18 // code here
19 // more examples at https://discord-buttons.js.org/
20})