![Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility](https://cdn.sanity.io/images/cgdhsj6q/production/97774ea8c88cc8f4bed2766c31994ebc38116948-1664x1366.png?w=400&fit=max&auto=format)
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
discord.js-better-components
Advanced tools
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
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.