/discord-buttons

A discord.js api for the discord buttons

Primary LanguageJavaScriptApache License 2.0Apache-2.0

NPM version NPM downloads

NPM Banner



Install

$ npm i discord-buttons

Setup

const discord = require('discord.js'); //Define the discord.js module
const client = new discord.Client(); //Creating discord.js client (constructor)
const disbut = require('discord-buttons')(client);

For more examples check our Documentation


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-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-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-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-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') //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

        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