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 ✨.
Starter provides functionality for initializing and starting a Discord bot 🤖.
Features:
- 🛠️ Handler for slash and prefix commands all in just two lines 🔩
- 📜 A list displaying all information(number of commands, events, and comprehensive bot) 🔍
- 🧰 Event handler in just one line 🎊
⚠️ Anti-crash system with error lock 📃- 🔋 Direct connection with MongoDB 📥
- 📑 Logging for slash and prefix command usage with comprehensive information 🧭
⚠️ NOTE:
Any option you don't want, justDELETE 🗑️
the optionLINE ➖
!
Quick setup ⚡
const { Starter } = require('djs-builder'); // cjs module .js
const { Client, GatewayIntentBits, Partials } = require('discord.js');
const client = new Client({
intents: Object.keys(GatewayIntentBits).map((a) => {
return GatewayIntentBits[a];
}),
});
// Define starter options
const starterOptions = {
bot: {
token: 'YOUR_BOT_TOKEN', // [OPTIONAL] Discord bot token
logs: {
terminal: true // [OPTIONAL] Log messages to terminal
},
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: '/database/folder', // Required: Path to database folder [Note: "Not path to file!"]
dev: {
enable: true, // Required: Enable development mode
logsPath: '/path/to/logs' // [OPTIONAL] Path to development logs [Note: "It will create logs file for database executions 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
}
};
const bot = new Starter();
bot.start(client, starterOptions);
ALL Options ⚙️
const { Starter } = require('djs-builder'); // cjs module .js
const { Client, GatewayIntentBits, Partials } = require('discord.js');
const client = new Client({
intents: Object.keys(GatewayIntentBits).map((a) => {
return GatewayIntentBits[a];
}),
});
// 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: '/database/folder', // Required: Path to database folder [Note: "Not path to file!"]
dev: {
enable: true, // Required: Enable development mode
logsPath: '/path/to/logs' // [OPTIONAL] Path to development logs [Note: "It will create logs file for database executions 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()
Build 🔵Button , 🧾Menu or 🏅PermissionChecker
- Easyest ✨
- Fastest ⚡
- Clear 🧵
Than the discord.js
🔵 ButtonManager
🔵 ButtonManager is a utility class for managing the creation of Discord buttons ✨.
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
🧾 MenuManager facilitates the creation of select menus (dropdown menus) in Discord ✨.
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
PermissionChecker provides functionality for checking user permissions in a Discord guild ✨.
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)
- Slash 🔧
Options
- Cooldown ⏳
- Prefix ➕
Options
- Cooldown ⏳
- Owner 👑
- Usage 🙎♂️
- Description 📜
- Category 📁
- Events 🎊
Options
- intializer
- retryAttempts
- execute once
- execute for specific times
- timeout
- name
Contributions are welcome! If you have any suggestions, bug reports, or feature requests, feel free to contact us on discord.