Discord Bot Utils

A comprehensive utility package for Discord.js bots that provides advanced features and helpers.

npm install @zerrodevs/discord-bot-utils

Features

Moderation

  • User timeout management
  • Message bulk deletion
  • Slowmode control
  • Permission validation

Interaction

  • Interactive polls
  • Role information
  • Button management
  • Vote tracking

Logging

  • Error tracking
  • Command logging
  • Webhook integration
  • File-based logs

Quick Examples

Moderation Example


const { ModerationUtil } = require('@zerrodevs/discord-bot-utils');

// Timeout a user
await ModerationUtil.timeout(member, 3600, 'Breaking rules');

// Clear messages
await ModerationUtil.clearMessages(channel, 100, {
	user: targetUser,
	contains: 'spam'
});
				

Poll Example


const { InteractionUtil } = require('@zerrodevs/discord-bot-utils');

// Create a poll
const poll = InteractionUtil.createPoll('What\'s your favorite color?', 
	['Red', 'Blue', 'Green']
);

const message = await channel.send({
	embeds: [poll.embed],
	components: poll.components
});
				

Installation

Install the package using npm:

npm install @zerrodevs/discord-bot-utils

Basic Usage


const { ModerationUtil, InteractionUtil, LoggerUtil } = require('@zerrodevs/discord-bot-utils');

// Initialize logger
await LoggerUtil.initialize({
	logDirectory: 'logs',
	webhookUrl: process.env.LOG_WEBHOOK_URL
});

// Use utilities
client.on('ready', () => {
	LoggerUtil.log('info', 'Bot is ready!');
});
				

Moderation Utils


// Timeout example
await ModerationUtil.timeout(member, 3600, 'Breaking rules');

// Clear messages example
await ModerationUtil.clearMessages(channel, 100, {
	user: targetUser,
	contains: 'spam'
});
				

Interaction Utils


// Create poll
const poll = InteractionUtil.createPoll('Question?', ['Yes', 'No']);

// Get role info
const roleInfo = await InteractionUtil.getRoleInfo(role);
				

Logging System


// Initialize logger
await LoggerUtil.initialize({
	logDirectory: 'logs',
	webhookUrl: 'your-webhook-url'
});

// Log events
await LoggerUtil.log('info', 'Operation successful');
await LoggerUtil.error(error, { context: 'Command execution' });
				

Preset Commands


const { PresetCommands } = require('@zerrodevs/discord-bot-utils');

// Get all preset commands
const commands = PresetCommands.getPresetCommands();

// Handle commands
client.on('interactionCreate', async interaction => {
	if (!interaction.isCommand()) return;
	
	switch(interaction.commandName) {
		case 'timeout':
			await PresetCommands.handleTimeout(interaction);
			break;
		case 'poll':
			await PresetCommands.handlePoll(interaction);
			break;
	}
});