Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
discord.js-better-components
Advanced tools
Readme
discord.js-better-components is a package that makes message components easier (and fun) to use.
Node.js 16.9.0 or newer is required.
npm i discord.js discord.js-better-components
With discord.js-better-components, five main "elements" are used:
When a button is clicked, it emits a "click" event with the MessageComponentInteraction
passed as an argument.
When a select menu option is clicked, it emits a "click" event and passes the MessageComponentInteraction
as well.
const { Button, ButtonStyles, ButtonBundle, Menu, MenuOption, Package } = require('discord.js-better-components');
const button = new Button({ label: 'My button', style: ButtonStyles.primary });
const bundle = new ButtonBundle([ button ]);
const option1 = new MenuOption({ label: 'Apples are better than oranges', description: 'If you say so...' });
const option2 = new MenuOption({ label: 'Oranges are better than apples', description: 'If you say so...' });
const menu = new Menu({ placeholder: 'Nothing selected', options: [ option1, option2 ]});
const package = new Package([ bundle, menu ], interaction.client);
button.on('click', i => console.log('My button was clicked!'));
option1.on('click', i => console.log(`${i.user.username} thinks that apples are better than oranges!`));
option2.on('click', i => console.log(`${i.user.username} thinks that oranges are better than apples!`));
await interaction.reply({ content: 'Here\'s a button!', components: package.format() });
Alternatively, if you're a masochist, here's how you do that exact same thing with discord.js:
const row = new Discord.MessageActionRow()
.addComponents(
new Discord.MessageButton()
.setLabel('My button')
.setCustomId('mybutton')
.setStyle('PRIMARY'),
);
const row2 = new MessageActionRow()
.addComponents(
new MessageSelectMenu()
.setCustomId('select')
.setPlaceholder('Nothing selected')
.addOptions([
{
label: 'Apples are better than oranges',
description: 'If you say so...',
value: 'apple_option',
},
{
label: 'Oranges are better than apples',
description: 'If you say so...',
value: 'orange_option',
},
]),
);
await interaction.reply({ content: 'Here\'s a button!', components: [row, row2] });
const filter = i => i.user.id == interaction.user.id;
const collector = interaction.channel.createMessageComponentCollector({ filter, time: 15000 });
collector.on('collect', i => {
if (i.customId == 'mybutton') {
console.log('My button was clicked!');
}
else if (i.customId == 'select') {
const optionPicked = i.values[0];
if (optionPicked == 'apple_option') {
console.log(`${i.user.username} thinks that apples are better than oranges!`);
}
else if (optionPicked == 'orange_option') {
console.log(`${i.user.username} thinks that oranges are better than apples!`);
}
}
});
Yeah, it's not pretty. Having to handle custom ID's, the huge constructors for action rows and components... it makes me shiver just thinking about it.
FAQs
A package that simplifies the use of message components
The npm package discord.js-better-components receives a total of 0 weekly downloads. As such, discord.js-better-components popularity was classified as not popular.
We found that discord.js-better-components demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.