ashthefennecfox

bot

Kodari AI
KodariApr 18 at 2:53 pm 8,118 (v2)

Iโ€™ll create a feature-rich modular Discord bot with commands and event handling.

ModularDiscordBot
A feature-rich Discord bot built with discord.js that provides comprehensive moderation, utility, and entertainment commands. Includes automated welcome messages for new members, powerful moderation tools like kick/ban with reason logging, fun commands like dice rolling and 8ball predictions, utility features including server info and user lookup, and detailed event logging for server activity. Designed with a modular command handler architecture for easy expansion and maintenance. Perfect for community servers needing a reliable all-in-one bot solution.

Project created with modular command and event handling system. Install dependencies with npm install, create a .env file with your Discord token, and run with npm start.

Kodari can make mistakes. Review important code before using.
Files
commands
events
utils
.gitignore
config.json
index.js
package.json
Code
16 512
index.js
const { Client, GatewayIntentBits, Collection } = require('discord.js');
const fs = require('fs');
const path = require('path');
require('dotenv').config();

const config = require('./config.json');
const logger = require('./utils/logger');

const client = new Client({
    intents: [
        GatewayIntentBits.Guilds,
        GatewayIntentBits.GuildMessages,
        GatewayIntentBits.GuildMembers,
        GatewayIntentBits.MessageContent
    ]
});

client.commands = new Collection();
client.config = config;

const loadCommands = () => {
    const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
    
    for (const file of commandFiles) {
        const command = require(`./commands/${file}`);
        client.commands.set(command.name, command);
        logger.info(`Loaded command: ${command.name}`);
    }
};

const loadEvents = () => {
    const eventFiles = fs.readdirSync('./events').filter(file => file.endsWith('.js'));
    
    for (const file of eventFiles) {
        const event = require(`./events/${file}`);
        if (event.once) {
            client.once(event.name, (...args) => event.execute(...args, client));
        } else {
            client.on(event.name, (...args) => event.execute(...args, client));
        }
        logger.info(`Loaded event: ${event.name}`);
    }
};

loadCommands();
loadEvents();

client.on('error', error => {
    logger.error('Client error:', error);
});

process.on('unhandledRejection', error => {
    logger.error('Unhandled promise rejection:', error);
});

client.login(process.env.DISCORD_TOKEN);