npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

discobase

v1.0.3

Published

Discobase is a powerful Node.js package for creating customizable Discord buttons and embed templates. It simplifies the process of sending Discord embeds and buttons with dynamic interaction handling, making it easier to create engaging Discord bot exper

Downloads

229

Readme

Discobase

Discobase is a powerful and easy-to-use Node.js package that simplifies the process of creating Discord embeds and buttons for your bot. Whether you are building a community bot, a utility bot, or a game bot, Discobase provides pre-made templates for embeds and buttons, making it incredibly easy to send interactive messages to your server.

Features

  • Pre-Made Embed Templates: Create beautiful and customizable embeds for success, info, warning, error, and more.
  • Button Interactions: Easily create buttons with custom emojis, styles, and actions. Handle button clicks directly in your code without complex event handling.
  • Minimal Code: Focus on your bot’s logic and let Discobase handle the boilerplate embed and button creation.
  • Customizable: Customize embed content, colors, and buttons to suit your specific needs.

Installation

To get started, you can install Discobase from npm:

npm install discobase

Usage

Create Embeds

Discobase provides a set of predefined embed templates for you to use directly. You can customize each template with a message or other options.

Example 1: Success Embed

const { EmbedBase } = require('discobase');

const embed = EmbedBase.create('success', 'Your operation was successful!');
channel.send({ embeds: [embed] });

Example 2: Info Embed

const { EmbedBase } = require('discobase');

const embed = EmbedBase.create('info', 'This is some information!');
channel.send({ embeds: [embed] });

Available Embed Templates

  • Success: A green embed used to show successful actions.
  • Info: A blue embed for informational messages.
  • Warning: An orange embed for warnings.
  • Error: A red embed for error messages.
  • Neutral: A default white embed for neutral messages.
  • Action Required: A purple embed for actions that require user interaction.

Example: Warning Embed

const { EmbedBase } = require('discobase');

const embed = EmbedBase.create('warning', 'This is a warning message!');
channel.send({ embeds: [embed] });

Create Buttons

Discobase makes it simple to create buttons with custom actions. Here's how to create a button and send it along with an interaction handler.

First make sure to pass client to ButtonBase. You can do it in your main bot file.

const { ButtonBase } = require('discobase')
ButtonBase.attachListener(client);

Example 1: Creating a Button

const { ButtonBase } = require('discobase');
const { ButtonStyle } = require('discord.js');

const button = new ButtonBase()
    .setEmoji('👍')
    .setStyle(ButtonStyle.Primary)
    .setCustomId('button1'); 

const buttonRow = button.build();
await interaction.reply({ components: [buttonRow] });

Button Interaction Handling

You can handle interactions for multiple or single buttons by registering them using ButtonBase.registerButton():

Single Button Example:

const { ButtonBase } = require('discobase');
const { ButtonStyle } = require('discord.js');

const button = new ButtonBase()
    .setEmoji('👍')
    .setStyle(ButtonStyle.Primary)
    .setCustomId('button1'); 

const buttonRow = button.build();
await interaction.reply({ components: [buttonRow] });

ButtonBase.registerButton('button', button);

button.onClick(async (interaction) => {
    await interaction.reply('You clicked the first button!');
});

Multiple Buttons

You can also send multiple buttons in the same message. Just create as many buttons as you need and use the Buttons.build() method to add them to a row.

Example: Multiple Buttons

const { ButtonBase } = require('discobase');
const { ButtonStyle } = require('discord.js');

const button1 = new ButtonBase()
    .setEmoji('👍')
    .setStyle(ButtonStyle.Primary)
    .setCustomId('button1'); 

const button2 = new ButtonBase()
    .setEmoji('❌')
    .setStyle(ButtonStyle.Danger)
    .setCustomId('button2'); 

const buttonRow = ButtonBase.build(button1, button2);
await interaction.reply({ components: [buttonRow] });

ButtonBase.registerButton('button1', button1);
ButtonBase.registerButton('button2', button2);

button1.onClick(async (interaction) => {
    await interaction.reply('You clicked the first button!');
});

button2.onClick(async (interaction) => {
    await interaction.reply('You clicked the second button!');
});

Contact

If you have any questions or need support, feel free to reach out to us:

  • Discord : https://discord.gg/ethical-programmer-s-1188398653530984539