New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

djs-builder

Package Overview
Dependencies
Maintainers
1
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

djs-builder

Discord.js bot builder. Supports Ts and Js.

  • 0.2.5
  • npm
  • Socket score

Version published
Weekly downloads
7
decreased by-88.14%
Maintainers
1
Weekly downloads
 
Created
Source

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

Starter

Description

Starter provides functionality for initializing and starting a Discord bot.

Usage

const { Starter } = require('djs-builder'); // cjs module .js
// 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: ['blacklistedEvent1', 'blacklistedEvent2'] // [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();

// Start the bot
const botstarted = bot.start(client, starterOptions)

// console.log(botstarted) 
    // return {
    //    mongodb
    //    versedb
    //    slashSize
    //    prefixSize
    //    eventSize
    // };

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)

Contributions

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

Discord Banner

Keywords

FAQs

Package last updated on 01 May 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc