Install
$ npm i discord-buttons
Setup
const discord = require('discord.js');
const client = new discord.Client();
const disbut = require('discord-buttons')(client);
For more examples check our Documentation
Example
let button = new disbut.MessageButton()
.setStyle('red')
.setLabel('My First Button!')
.setID('click_to_function')
.setDisabled();
message.channel.send('Hey, i am powered by https://npmjs.com/discord-buttons', button);
Multiple Buttons
let button = new disbut.MessageButton()
.setStyle('red')
.setLabel('My First Button!')
.setID('click_to_function')
.setDisabled();
let button2 = new disbut.MessageButton()
.setStyle('url')
.setLabel('My Second Button!')
.setURL('[click_to_function](https://npmjs.com/discord-buttons)')
message.channel.send('Hey, i am powered by https://npmjs.com/discord-buttons', {
buttons: [
button, button2
]
});
With embed
let myembed = new discord.MessageEmbed()
.setDescription('Hi!');
let btn = new disbut.MessageButton()
.setStyle('red')
.setLabel('My First Button!')
.setID('click_to_function')
.setDisabled();
message.channel.send('Hey, i am powered by https://npmjs.com/discord-buttons', { button: btn, embed: myembed });
Using command handler?
const { MessageButton } = require('discord-buttons');
module.exports = {
name: 'test',
run: async (client, message, args) => {
let button = new disbut.MessageButton()
.setStyle('red')
.setLabel('My First Button!')
.setID('click_to_function')
.setDisabled();
await message.channel.send('Hey, i am powered by https://npmjs.com/discord-buttons', button);
}
}
Handle Button
client.on('clickButton', async (button) => {
if (button.id === 'click_to_function') {
button.channel.send(`${button.clicker.user.tag} clicked button!`);
}
});
Note: don't forgot to put require('discord-buttons')(client)
after your client
Documentation
Checkout more examples on our docs
Don't see the buttons?
The buttons are beta, so to see them you have to be a discord-tester or just wait for the update
For any questions or errors, join in our server and report the bug on the #errors channel https://discord.gg/5JtyYqW
Contact
Youtube, Discord