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
- ButtonManager
- MenuManager
- PermissionChecker
- Starter
- Options
Starter
Description
Starter provides functionality for initializing and starting a Discord bot.
Usage
const { Starter } = require('djs-builder');
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),
});
import { Starter } from 'djs-builder';
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[],
});
const starterOptions = {
bot: {
token: 'YOUR_BOT_TOKEN',
logs: {
devLogs: {
enable: true,
pathToWatch: '/path/to/watch',
webhookURL: 'https://your.webhook.url',
mention: '<@123456789012345678>'
},
terminal: true
},
name: 'Your Bot Name',
avatar: 'https://your.bot/avatar.png',
banner: 'https://your.bot/banner.png',
BotInfo: {
perms: ['SendMessages', 'BotMessages'],
serverId: '123456789012345678',
botInvite: 'https://discord.com/invite/your-bot-invite',
serverInvite: 'https://discord.com/invite/your-server-invite',
ownerId: '123456789012345678',
partners: ['partner1', 'partner2']
},
Status: {
state: 'online',
activities: ['Game 1', 'Game 2'],
type: 0,
delay: 60000
},
Database: {
mongo: {
mongoURI: 'mongodb://localhost:27017',
dbName: 'your_database_name'
},
verse: {
adapterType: 'json',
path: '/path/to/json/file',
dev: {
enable: true,
logsPath: '/path/to/logs'
},
secure: { enable: false, secret:'your_encryption_key'}
}
}
},
slash: {
path: './path/to/slash_commands',
global: true,
serverId: '123456789012345678',
logsId: '123456789012345678'
},
prefix: {
path: './path/to/prefixes',
prefix: '!',
global: true,
serverIds: ['123456789012345678'],
logsId: '123456789012345678'
},
events: {
path: './path/to/events',
recursive: true,
eventBlacklist: ['path/to the event/file.js', 'path/to the event/file.js']
},
anticrash: {
enable: true,
webhookURL: 'https://your.crash.webhook.url',
mention: '<@123456789012345678>'
}
};
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 };
export { botStart };
- Usage for the returned values from botStart() funtion:
const { botStart } = require('path/to/file/where botStart is exported from');
import { botStart } from 'path/to/file/where botStart is exported from';
async function test() {
const client = await botStart();
const db = await client.getDb;
await db.collection('collectionName');
const db = await client.db;
await db.load('collectionName');
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');
import { ButtonManager } from 'djs-builder';
const buttonsData = [
{
customId: 'button1',
style: 'Primary',
label: 'Primary Button',
emoji: '😃',
disabled: false,
},
{
customId: 'button2',
style: 'Secondary',
label: 'Secondary Button',
emoji: '🚀',
disabled: true,
},
{
style: 'Link',
label: 'Link Button',
url: 'https://example.com',
emoji: '🔗',
},
];
const actionRow = new ButtonManager(buttonsData);
const row = actionRow.ButtonBuild();
const message = await interaction.channel.send({ content: 'Here are some buttons:', components: [row] });
const message = await message.channel.send({ content: 'Here are some buttons:', components: [row] });
Description
MenuManager facilitates the creation of select menus (dropdown menus) in Discord.
Usage
const { MenuManager } = require('djs-builder');
import { MenuManager } from 'djs-builder';
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: '🔗' },
];
const selectMenuManager = new MenuManager(
selectMenuOptions,
'customSelectMenuId',
'Select an option',
1,
2,
false
);
const selectMenuRow = selectMenuManager.createSelectMenu();
message.reply({
content: 'Please choose an option:',
components: [selectMenuRow],
});
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');
import { PermissionChecker } from 'djs-builder';
const perms = new PermissionChecker();
const userId = interaction.user.id;
const guild = interaction.guild;
const guild = message.guild;
const memberId = message.author.id;
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.