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 :)
1client.on('message', message => {
2if(message.content.startsWith(prefix + "ticket-message")) {
3 let btn1 = new disbut.MessageButton()
4 .setStyle('red')
5 .setEmoji(":ticket:")
6 .setID('1')
7 message.delete()
8 message.channel.send(`react here to open a ticket`, btn1)
9 }
10})
11client.on('clickButton', async (button) => {
12 await button.defer();
13 if(button.id === "1") {
14 let btn2 = new disbut.MessageButton()
15 .setLabel('close')
16 .setStyle('red')
17 .setEmoji(":x:")
18 .setID('2')
19 button.guild.channels.create(`${button.clicker.user.username} ticket`, {
20 permissionOverwrites: [
21 {
22 id: button.guild.roles.everyone,
23 deny: ['VIEW_CHANNEL'],
24 },
25 {
26 id: button.clicker.user.id,
27 allow: ['VIEW_CHANNEL'],
28 },
29 ],
30}).then(channel => {
31 channel.send(`**please wait for our support team \n react with the emoji to close the ticket**`, btn2)
32
33 })
34
35 }
36 if(button.id === "2") {
37
38 button.channel.send("deleting after 5 seconds")
39 setTimeout(function() {
40 button.channel.delete();
41 }, 5000)
42 }
43})