discord.js-buttons
v1.0.0
Published
HunterRock Discord.js Buttons
Downloads
256
Maintainers
Readme
DISCORD.JS-BUTTONS
Instal
$ npm i discord.js-buttons
Setup
const discord = require('discord.js');
const client = new discord.Client();
const disbut = require('discord.js-buttons')(client);
Example
let button = new disbut.MessageButton()
.setStyle('red') //default: blurple
.setLabel('My First Button!') //default: NO_LABEL_PROVIDED
.setID('click_to_function') //note: if you use the style "url" you must provide url using .setURL('https://example.com')
.setDisabled(); //disables the button | default: false
message.channel.send('Hey, i am powered by https://npmjs.com/discord.js-buttons', button);
Multiple Buttons
let button = new disbut.MessageButton()
.setStyle('red') //default: blurple
.setLabel('My First Button!') //default: NO_LABEL_PROVIDED
.setID('click_to_function') //note: if you use the style "url" you must provide url using .setURL('https://example.com')
.setDisabled(); //disables the button | default: false
let button2 = new disbut.MessageButton()
.setStyle('url') //default: blurple
.setLabel('My Second Button!') //default: NO_LABEL_PROVIDED
.setURL('[click_to_function](https://npmjs.com/discord.js-buttons)') //note: if you use other style you must provide id using .setID('myid')
message.channel.send('Hey, i am powered by https://npmjs.com/discord.js-buttons', {
buttons: [
button, button2
]
});
With embed
let myembed = new discord.MessageEmbed()
.setDescription('Hi!');
let btn = new disbut.MessageButton()
.setStyle('red') //default: blurple
.setLabel('My First Button!') //default: NO_LABEL_PROVIDED
.setID('click_to_function') //note: if you use the style "url" you must provide url using .setURL('https://example.com')
.setDisabled(); //disables the button | default: false
message.channel.send('Hey, i am powered by https://npmjs.com/discord.js-buttons', { button: btn, embed: myembed });
Handle Button
client.on('clickButton', async (button) => {
if (button.id === 'click_to_function') {
button.channel.send(`${button.clicker.user.tag} clicked button!`);
}
});
Original License
GitHub AngeloCore