1.0.5 • Published 2 years ago
discord.js-better-buttons v1.0.5
PLEASE DO NOT USE THIS PACKAGE YET ITS NOT FINISHED!!!!!!!!
About
discord.js-better-buttons is a package that makes message buttons easier (and fun) to use.
Features
- a
Installation
npm i discord.js discord.js-better-buttons
Example Comparison
If you want to create and use a button with just discord.js, here's how you currently do it:
const row = new Discord.MessageActionRow()
.addComponents(
new Discord.MessageButton()
.setLabel('My button')
.setCustomId('mybutton')
.setStyle('PRIMARY'),
);
await interaction.reply({ content: 'Here\'s a button!', components: [row] });
const filter = i => i.user.id == interaction.user.id;
const collector = interaction.channel.createMessageComponentCollector({ filter, time: 15000 });
collector.on('collect', async i => {
if (i.customId == 'mybutton') {
console.log('A button was clicked!');
}
});
That's cool and all, but it could be better. Here's how you can create and send a button using discord.js-better-buttons:
const { Button, ButtonBundle, ButtonPackage, ButtonStyles } = require('discord.js-better-buttons');
const button = new Button({ label: 'My button', style: ButtonStyles.primary });
const bundle = new ButtonBundle([ button ]);
const package = new ButtonPackage([ bundle ], interaction.client);
button.on('click', async i =>{
console.log('A button was clicked!');
});
await interaction.reply({ content: 'Here\'s a button!', components: package.format() });
Yes, yes, I know. It's amazing. But you know what's even more amazing? Your code, once you start using this package!