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

djs-builder

v0.3.11

Published

Discord.js bot builder. Supports Ts and Js.

Downloads

845

Readme

Discord Bot Utilities

Welcome to the Discord Bot Utilities package! This package provides a set of utility classes/interfaces to simplify common tasks when developing Discord bots using the Discord.js library.

Table of Contents

  1. ButtonManager
  2. MenuManager
  3. PermissionChecker
  4. Starter
  5. Options

Starter

Description

Starter provides functionality for initializing and starting a Discord bot.

Usage

const { Starter } = require('djs-builder'); // cjs module .js

const { Client, GatewayIntentBits, Partials } = require('discord.js');

const intentsArray = Object.keys(GatewayIntentBits)
    .map((a) => GatewayIntentBits[a]);
const intents = intentsArray.reduce((acc, curr) => acc | curr, 0);

const client = new Client({
    intents,
    partials: Object.values(Partials),
});

// OR
import { Starter } from 'djs-builder'; // Ejs module .mjs or Ts

import { Client, GatewayIntentBits, Partials, PermissionFlagsBits } from 'discord.js';

const intentsArray = Object.keys(GatewayIntentBits)
    .map((a) => GatewayIntentBits[a as keyof typeof GatewayIntentBits]);
const intents = intentsArray.reduce((acc, curr) => acc | curr, 0);

const client = new Client({
    intents,
    partials: Object.values(Partials) as Partials[],
});

// Define starter options
const starterOptions = {
    bot: {
        token: 'YOUR_BOT_TOKEN', // [OPTIONAL] Discord bot token
        logs: {
            devLogs: {
                enable: true, // Required: Enable developer logs
                pathToWatch: '/path/to/watch', // Required: Path to watch for file changes
                webhookURL: 'https://your.webhook.url', // Required: Webhook URL for logging
                mention: '<@123456789012345678>' // [OPTIONAL] User ID to mention in logs
            },
            terminal: true // [OPTIONAL] Log messages to terminal
        },
        name: 'Your Bot Name', // [OPTIONAL] Bot name
        avatar: 'https://your.bot/avatar.png', // [OPTIONAL] Bot avatar URL or local path image
        banner: 'https://your.bot/banner.png', // [OPTIONAL] Bot banner URL or local path image
        BotInfo: {
            perms: ['SendMessages', 'BotMessages'], // [OPTIONAL] Bot permissions to work in any server
            serverId: '123456789012345678', // [OPTIONAL] Discord server ID
            botInvite: 'https://discord.com/invite/your-bot-invite', // [OPTIONAL] Bot invite URL
            serverInvite: 'https://discord.com/invite/your-server-invite', // [OPTIONAL] Server invite URL
            ownerId: '123456789012345678', // [OPTIONAL] Bot owner's user ID
            partners: ['partner1', 'partner2'] // [OPTIONAL] Bot partners
        },
        Status: {
            state: 'online', // Required: Bot presence state ['online', 'offline', 'dnd', 'idle', 'Streaming']
            activities: ['Game 1', 'Game 2'], // [OPTIONAL] Bot activities
            type: 0, // [OPTIONAL] Bot activity type
            delay: 60000 // [OPTIONAL] Activity rotation delay in milliseconds
        },
        Database: {
            mongo: {
                mongoURI: 'mongodb://localhost:27017', // Required: MongoDB connection URI
                dbName: 'your_database_name' // [OPTIONAL] MongoDB database name
            },
            verse: {
                adapterType: 'json', // Required: Database adapter type ['json', 'yaml', 'sql']
                path: '/path/to/json/file', // Required: Path to database file
                dev: {
                    enable: true, // Required: Enable development mode
                    logsPath: '/path/to/logs' // [OPTIONAL] Path to development logs
                },
                secure: { enable: false, secret:'your_encryption_key'} // [OPTIONAL] To secure Data File by encrypting it with secret key
            }
        }
    },
    slash: {
        path: './path/to/slash_commands', // Required: Path to slash commands
        global: true, // [OPTIONAL] Register slash commands globally
        serverId: '123456789012345678', // [OPTIONAL] Discord server ID
        logsId: '123456789012345678' // [OPTIONAL] Logs channel ID
    },
    prefix: {
        path: './path/to/prefixes', // Required: Path to prefix settings
        prefix: '!', // Required: Default bot prefix
        global: true, // [OPTIONAL] Use global prefix
        serverIds: ['123456789012345678'], // [OPTIONAL] Discord server IDs
        logsId: '123456789012345678' // [OPTIONAL] Logs channel ID
    },
    events: {
        path: './path/to/events', // Required: Path to event handlers
        recursive: true, // [OPTIONAL] Enable recursive event loading
        eventBlacklist: ['path/to the event/file.js', 'path/to the event/file.js'] // [OPTIONAL] Blacklisted events
    },
    anticrash: {
        enable: true, // Required: Enable anti-crash feature
        webhookURL: 'https://your.crash.webhook.url', // Required: Webhook URL for crash alerts
        mention: '<@123456789012345678>' // [OPTIONAL] User ID to mention in crash alerts
    }
};

// Define the starter instance
const bot = new Starter();

async function botStart() {
const botstarted = await bot.start(client, starterOptions);
    const mongodb = await botstarted.mongodb;
    const versedb = await botstarted.versedb;
    const slashSize = await botstarted.slashSize;
    const prefixSize = await botstarted.prefixSize;
    const eventSize = await botstarted.eventSize;
    return {
        getDb: mongodb,
        db: versedb,
        slashSize: slashSize,
        prefixSize: prefixSize,
        eventSize: eventSize
    }
}
module.exports = { botStart };
// Or
export { botStart };
  • Usage for the returned values from botStart() funtion:
const { botStart } = require('path/to/file/where botStart is exported from');
// Or
import { botStart } from 'path/to/file/where botStart is exported from';

async function test() {
    const client = await botStart();

    // Usage for mongoDb
    const db = await client.getDb;
    await db.collection('collectionName'); // See more usage at https://www.mongodb.com

    // Usage for verseDb
    const db = await client.db;
    await db.load('collectionName'); // See more usage at https://versedb.jedi-studio.com

    // Usage for slashSize/prefixSize/eventSize
    console.log(`loaded slash Commands: ${client.slashSize}`);
    console.log(`loaded prefix Commands: ${client.prefixSize}`);
    console.log(`loaded events: ${client.eventSize}`);
}

test()

ButtonManager

Description

ButtonManager is a utility class for managing the creation of Discord buttons.

Usage

const { ButtonManager } = require('djs-builder'); // Cjs module .js
// OR
import { ButtonManager } from 'djs-builder'; // Ejs module .mjs or Ts

// Define button data
const buttonsData = [
  {
    customId: 'button1',
    style: 'Primary',// style: Primary, Secondary, Link, Danger, Success
    label: 'Primary Button',
    emoji: '😃',  // Emoji for the button
    disabled: false,  // Whether the button is disabled
  },
  {
    customId: 'button2',
    style: 'Secondary',
    label: 'Secondary Button',
    emoji: '🚀',
    disabled: true,
  },
  {
    style: 'Link',
    label: 'Link Button',
    url: 'https://example.com',  // URL for link-style button
    emoji: '🔗',
  },
];

// Create an instance of ButtonManager
const actionRow = new ButtonManager(buttonsData);

// Buttons Row add it into components
const row = actionRow.ButtonBuild();

// Exmaple 
const message = await interaction.channel.send({ content: 'Here are some buttons:', components: [row] });
// OR
const message = await message.channel.send({ content: 'Here are some buttons:', components: [row] });

MenuManager

Description

MenuManager facilitates the creation of select menus (dropdown menus) in Discord.

Usage

const { MenuManager } = require('djs-builder'); // Cjs module .js
// OR
import { MenuManager } from 'djs-builder'; // Ejs module .mjs or ts

// Define select menu options
const selectMenuOptions = [
  { label: 'Option 1', value: 'option1', description: 'Description for Option 1', emoji: '🌟', default: true },
  { label: 'Option 2', value: 'option2', description: 'Description for Option 2', emoji: '🚀' },
  { label: 'Option 3', value: 'option3', description: 'Description for Option 3', emoji: '🔗' },
];

// Create an instance of SelectMenuManager
const selectMenuManager = new MenuManager(
  selectMenuOptions,
  'customSelectMenuId',  // Custom ID for the select menu
  'Select an option',    // Placeholder text for the select menu
  1,                      // Minimum number of selected values
  2,                       // Maximum number of selected values
  false                   // Disabled state for meny (true or false)
);

// Create a select menu with the specified options
const selectMenuRow = selectMenuManager.createSelectMenu();

// Define a message with the select menu
 message.reply({
  content: 'Please choose an option:',
  components: [selectMenuRow],
});

// Define a interaction with the select menu
 interaction.reply({
  content: 'Please choose an option:',
  components: [selectMenuRow],
});

PermissionChecker

Description:

PermissionChecker provides functionality for checking user permissions in a Discord guild.

Usage:

const { PermissionChecker } =  require('djs-builder'); // Cjs module .js
// OR
import { PermissionChecker } from 'djs-builder'; // Ejs module .mjs or ts

const perms = new PermissionChecker();

// Interaction case
const userId = interaction.user.id;
const guild = interaction.guild;
// Message Case
const guild = message.guild;
const memberId = message.author.id;

// Usage:

const permToCheck = ['ManageGuild', 'BanMembers']
perms.checker(userId, guild, permToCheck)

Options:

  • Cooldown in slash/prefix commands.
  • Owner, Usage, Description, and Category for prefix commands
  • Events has intializer, retryAttempts, execute once, execute for specific times, timeout, and name

Contributions

Contributions are welcome! If you have any suggestions, bug reports, or feature requests, feel free to contact us on discord.

Discord Banner