yepimnoob
📎 1 file 1,814 chars
📄
pasted-code-1769543509473.txt
txt 81 lines
▶
Create a Discord bot in JavaScript using discord.js with the following requirements:

User Restrictions:

Only users with IDs 1295021931744989350 and 1097199259742392433 can use commands.

Other users attempting commands should get a polite embed saying they cannot use this bot.

Configuration:

Use a config.json to store:

Bot token

Command prefix

Messages for all commands

Embed colors, titles, footers, and formatting

Commands:

!to @user time reason → Timeout a user

!ban @user reason → Ban a user

!tban @user time reason or !tempban @user time reason → Temporary ban a user

!unban @user reason → Unban a user

!kick @user reason → Kick a user

!mute @user time reason → Mute a user

!unmute @user → Unmute a user

!nick @user newnickname → Change a user’s nickname

!say message → Bot repeats a message in an embed

!lockchannel → Lock the current channel

!unlockchannel → Unlock the current channel

!ping → Show bot latency

!avatar @user → Show user’s avatar

!serverinfo → Show server info in an embed

!botinfo → Show bot info

!slowmode time → Set the channel slowmode

!poll question | option1 | option2 | ... → Create a poll

!clear number → Bulk delete messages

!embed title | description → Bot sends a custom embed

!react @message emoji → Bot reacts to a message with an emoji

!flipcoin → Bot flips a coin

!roll number → Bot rolls a dice up to the number

!quote message → Bot quotes a message in an embed

!dm @user message → Bot DMs a user

!eval code → Run JavaScript code (for the two owners only)

Features:

All outputs use rich embeds with configurable colors, titles, footers, and timestamps from config.json

Proper error handling for invalid users, missing arguments, or permissions

Lightweight and private for only two users

Easy to expand with additional private commands
Kodari AI
KodariJan 27 at 7:53 pm 8,036 (v2)

I’ll create a private Discord moderation bot for two authorized users with comprehensive commands and rich embeds.

PrivateModBot
A private Discord moderation bot designed for two authorized users. Features comprehensive moderation tools including timeout, ban, kick, mute, and channel management. Includes utility commands like polls, embeds, server info, and fun commands. All outputs use customizable rich embeds with configurable colors, titles, and footers. Lightweight design with proper permission handling and error management for private use.

Bot created successfully! Here’s what was included:

Files Created:

  • bot.js - Main bot with all 24 commands

  • config.json - Fully configured with messages, embed settings, and authorized user IDs

  • package.json - Dependencies (discord.js v14 + dotenv)

  • .env - Token storage

  • .gitignore - Protects sensitive files

  • README.md - Setup instructions

Features: ✅ Only authorized users (your two IDs) can use commands ✅ All outputs use rich embeds with custom colors and footers ✅ Comprehensive moderation tools (timeout, ban, tempban, kick, mute) ✅ Utility commands (polls, embeds, server info, avatar) ✅ Fun commands (coin flip, dice roll, quote) ✅ eval command for code execution (owners only) ✅ Proper error handling throughout ✅ Easy to customize via config.json

Setup:

  1. Run npm install

  2. Replace token in .env file

  3. Run npm start

Kodari can make mistakes. Review important code before using.
Files
.gitignore
bot.js
config.json
package.json
README.md
Code
5 622
bot.js
const { Client, GatewayIntentBits, EmbedBuilder, PermissionFlagsBits, ChannelType } = require('discord.js');
const fs = require('fs');
require('dotenv').config();

const config = JSON.parse(fs.readFileSync('./config.json', 'utf8'));

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

const tempBans = new Map();

function isAuthorized(userId) {
    return config.authorizedUsers.includes(userId);
}

function createEmbed(title, description, color = config.embedColor) {
    return new EmbedBuilder()
        .setTitle(title)
        .setDescription(description)
        .setColor(color)
        .setFooter({ text: config.embedFooter })
        .setTimestamp();
}

function parseTime(timeStr) {
    const match = timeStr.match(/^(\d+)([smhd])$/);
    if (!match) return null;
    
    const value = parseInt(match[1]);
    const unit = match[2];
    
    const multipliers = {
        's': 1000,
        'm': 60000,
        'h': 3600000,
        'd': 86400000
    };
    
    return value * multipliers[unit];
}

function formatTime(ms) {
    const seconds = Math.floor(ms / 1000);
    const minutes = Math.floor(seconds / 60);
    const hours = Math.floor(minutes / 60);
    const days = Math.floor(hours / 24);
    
    if (days > 0) return `${days} day(s)`;
    if (hours > 0) return `${hours} hour(s)`;
    if (minutes > 0) return `${minutes} minute(s)`;
    return `${seconds} second(s)`;
}

client.once('ready', () => {
    console.log(`Bot is ready! Logged in as ${client.user.tag}`);
    client.user.setActivity('Private Moderation Bot');
});

client.on('messageCreate', async (message) => {
    if (message.author.bot) return;
    if (!message.content.startsWith(config.prefix)) return;

    const args = message.content.slice(config.prefix.length).trim().split(/ +/);
    const command = args.shift().toLowerCase();

    if (!isAuthorized(message.author.id)) {
        const embed = createEmbed(
            config.messages.unauthorized.title,
            config.messages.unauthorized.description,
            '#FF0000'
        );
        return message.reply({ embeds: [embed] });
    }

    try {
        if (command === 'to' || command === 'timeout') {
            const member = message.mentions.members.first();
            const time = args[1];
            const reason = args.slice(2).join(' ') || 'No reason provided';

            if (!member || !time) {
                return message.reply({ embeds: [createEmbed(config.messages.error.title, 'Usage: !to @user time reason', '#FF0000')] });
            }

            const duration = parseTime(time);
            if (!duration) {
                return message.reply({ embeds: [createEmbed(config.messages.error.title, 'Invalid time format. Use: 30s, 5m, 2h, 1d', '#FF0000')] });
            }

            await member.timeout(duration, reason);
            const embed = createEmbed(
                config.messages.timeout.title,
                config.messages.timeout.description
                    .replace('{user}', member.user.tag)
                    .replace('{duration}', formatTime(duration))
                    .replace('{reason}', reason)
            );
            return message.reply({ embeds: [embed] });
        }

        if (command === 'ban') {
            const member = message.mentions.members.first();
            const reason = args.slice(1).join(' ') || 'No reason provided';

            if (!member) {
                return message.reply({ embeds: [createEmbed(config.messages.error.title, 'Usage: !ban @user reason', '#FF0000')] });
            }

            await member.ban({ reason });
            const embed = createEmbed(
                config.messages.ban.title,
                config.messages.ban.description
                    .replace('{user}', member.user.tag)
                    .replace('{reason}', reason)
            );
            return message.reply({ embeds: [embed] });
        }

        if (command === 'tban' || command === 'tempban') {
            const member = message.mentions.members.first();
            const time = args[1];
            const reason = args.slice(2).join(' ') || 'No reason provided';

            if (!member || !time) {
                return message.reply({ embeds: [createEmbed(config.messages.error.title, 'Usage: !tban @user time reason', '#FF0000')] });
            }

            const duration = parseTime(time);
            if (!duration) {
                return message.reply({ embeds: [createEmbed(config.messages.error.title, 'Invalid time format. Use: 30s, 5m, 2h, 1d', '#FF0000')] });
            }

            await member.ban({ reason: `Temporary ban: ${reason}` });
            tempBans.set(member.id, { guildId: message.guild.id, unbanAt: Date.now() + duration });
            
            setTimeout(async () => {
                try {
                    await message.guild.members.unban(member.id, 'Temporary ban expired');
                    tempBans.delete(member.id);
                } catch (err) {
                    console.error('Failed to unban user:', err);
                }
            }, duration);

            const embed = createEmbed(
                config.messages.tempban.title,
                config.messages.tempban.description
                    .replace('{user}', member.user.tag)
                    .replace('{duration}', formatTime(duration))
                    .replace('{reason}', reason)
            );
            return message.reply({ embeds: [embed] });
        }

        if (command === 'unban') {
            const userId = args[0];
            const reason = args.slice(1).join(' ') || 'No reason provided';

            if (!userId) {
                return message.reply({ embeds: [createEmbed(config.messages.error.title, 'Usage: !unban userId reason', '#FF0000')] });
            }

            const bannedUser = await message.guild.bans.fetch(userId).catch(() => null);
            if (!bannedUser) {
                return message.reply({ embeds: [createEmbed(config.messages.error.title, 'User is not banned', '#FF0000')] });
            }

            await message.guild.members.unban(userId, reason);
            const embed = createEmbed(
                config.messages.unban.title,
                config.messages.unban.description
                    .replace('{user}', bannedUser.user.tag)
                    .replace('{reason}', reason)
            );
            return message.reply({ embeds: [embed] });
        }

        if (command === 'kick') {
            const member = message.mentions.members.first();
            const reason = args.slice(1).join(' ') || 'No reason provided';

            if (!member) {
                return message.reply({ embeds: [createEmbed(config.messages.error.title, 'Usage: !kick @user reason', '#FF0000')] });
            }

            await member.kick(reason);
            const embed = createEmbed(
                config.messages.kick.title,
                config.messages.kick.description
                    .replace('{user}', member.user.tag)
                    .replace('{reason}', reason)
            );