discord.js-button
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

DISCORD.JS-BUTTON

Instal

$ npm i discord.js-button

Setup

const discord = require('discord.js');
const client = new discord.Client();
const disbut = require('discord.js-button')(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-button', 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-button)') //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-button', {
  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-button', { 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

Package Sidebar

Install

npm i discord.js-button

Weekly Downloads

4

Version

1.0.0

License

MIT

Unpacked Size

26.1 kB

Total Files

24

Last publish

Collaborators

  • hunterrock