tinyhelius2

Make me a staff management bot with the following commands

/loa submit <starting date> <end date> <reason> which would send a loa request in a specific channel, the request should be an embed with the users name the reason, starting date and ending date. The embed should have two buttons: - Approve: which would approve the user's loa request and send that user an embed saying that their loa request was approved a LOA role should also be added to the user and removed when the loa has ended. - Deny: this would send an embed to the user saying that their LOA request was denied After the LOA was approved / denied the buttons should be removed and only the embed should be left.

Add a /staffinfo [name] [nickname] [position] which would send an embed with the info that they just put in.

Kodari AI
KodariJan 14 at 7:50 pm 4,179 (v2)

Iโ€™ll create a staff management Discord bot with LOA requests and staff info commands.

StaffManagementBot
A Discord bot for managing staff operations including Leave of Absence (LOA) requests with approval workflow and automatic role management. Features slash commands for submitting LOA requests with date ranges and reasons, interactive approval/denial buttons, automatic LOA role assignment and removal based on end dates, and staff information display commands. Includes embed-based user notifications and admin controls.

Created a complete staff management bot with:

Files created:

  • bot.js - Main bot with all commands and LOA system

  • package.json - Dependencies (discord.js, dotenv)

  • .env - Token storage

  • config.json - Channel and role configuration

  • README.md - Setup instructions

Features implemented:

  • /loa submit command with embeds and approve/deny buttons

  • Automatic LOA role addition on approval

  • DM notifications for approval/denial

  • Button removal after action

  • Automatic role removal when LOA expires

  • /staffinfo command with custom fields

Setup required:

  1. Run npm install

  2. Add your bot token to .env

  3. Update config.json with your LOA request channel ID and LOA role ID

  4. Run npm start

tinyhelius2

add a required role so only admins can approve or deny a LOA

if a user is on a LOA don't allow them to submit a new one

Kodari AI
KodariJan 14 at 8:12 pm 5,615 (v2)

Iโ€™ll read the current bot configuration and code to add admin role requirements and prevent duplicate LOAs.

Iโ€™ll update the bot to:

  1. Add an admin role requirement for approving/denying LOAs

  2. Prevent users who already have an active LOA from submitting a new one

Changes implemented:

  1. Added adminRoleId to config.json - you need to set this to your admin role ID

  2. Added role check in both handleLoaApprove and handleLoaDeny - only users with the admin role can approve/deny LOAs

  3. Added duplicate LOA prevention in handleLoaSubmit - checks both active LOAs and pending requests before allowing submission

tinyhelius2

Add a /loa list which would list all the people on a LOA and add a /loa return which would remove the LOA role and return you from LOA so you may submit a new one

tinyhelius2

Add a /loa list which would list all the people on a LOA and add a /loa return which would remove the LOA role and return you from LOA so you may submit a new one

Kodari can make mistakes. Review important code before using.
Files
bot.js
config.json
package.json
README.md
Code
4 357
bot.js
const { Client, GatewayIntentBits, SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, PermissionFlagsBits } = require('discord.js');
require('dotenv').config();
const config = require('./config.json');

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

const activeLoaRequests = new Map();
const activeLoas = new Map();

client.once('ready', async () => {
    console.log(`Bot is ready! Logged in as ${client.user.tag}`);
    
    const commands = [
        new SlashCommandBuilder()
            .setName('loa')
            .setDescription('Leave of Absence management')
            .addSubcommand(subcommand =>
                subcommand
                    .setName('submit')
                    .setDescription('Submit a LOA request')
                    .addStringOption(option =>
                        option.setName('starting_date')
                            .setDescription('Starting date (MM/DD/YYYY)')
                            .setRequired(true))
                    .addStringOption(option =>
                        option.setName('end_date')
                            .setDescription('End date (MM/DD/YYYY)')
                            .setRequired(true))
                    .addStringOption(option =>
                        option.setName('reason')
                            .setDescription('Reason for LOA')
                            .setRequired(true))),
        
        new SlashCommandBuilder()
            .setName('staffinfo')
            .setDescription('Display staff information')
            .addStringOption(option =>
                option.setName('name')
                    .setDescription('Staff member name')
                    .setRequired(true))
            .addStringOption(option =>
                option.setName('nickname')
                    .setDescription('Staff member nickname')
                    .setRequired(true))
            .addStringOption(option =>
                option.setName('position')
                    .setDescription('Staff position')
                    .setRequired(true))
    ];

    try {
        await client.application.commands.set(commands);
        console.log('Slash commands registered successfully');
    } catch (error) {
        console.error('Error registering slash commands:', error);
    }

    setInterval(checkExpiredLoas, 60000);
});

client.on('interactionCreate', async interaction => {
    if (interaction.isChatInputCommand()) {
        await handleSlashCommand(interaction);
    } else if (interaction.isButton()) {
        await handleButton(interaction);
    }
});

async function handleSlashCommand(interaction) {
    if (interaction.commandName === 'loa') {
        if (interaction.options.getSubcommand() === 'submit') {
            await handleLoaSubmit(interaction);
        }
    } else if (interaction.commandName === 'staffinfo') {
        await handleStaffInfo(interaction);
    }
}

async function handleLoaSubmit(interaction) {
    const user = interaction.user;

    if (activeLoas.has(user.id)) {
        await interaction.reply({ content: 'You already have an active LOA. Please wait until it expires before submitting a new one.', ephemeral: true });
        return;
    }

    if (activeLoaRequests.has(user.id)) {
        await interaction.reply({ content: 'You already have a pending LOA request. Please wait for it to be reviewed.', ephemeral: true });
        return;
    }

    const startingDate = interaction.options.getString('starting_date');
    const endDate = interaction.options.getString('end_date');
    const reason = interaction.options.getString('reason');

    const embed = new EmbedBuilder()
        .setColor('#FFA500')
        .setTitle('๐Ÿ—“๏ธ LOA Request')
        .addFields(
            { name: 'User', value: `${user.tag} (${user.id})`, inline: false },
            { name: 'Starting Date', value: startingDate, inline: true },
            { name: 'End Date', value: endDate, inline: true },
            { name: 'Reason', value: reason, inline: false }
        )
        .setTimestamp()
        .setFooter({ text: `Requested by ${user.tag}`, iconURL: user.displayAvatarURL() });

    const approveButton = new ButtonBuilder()
        .setCustomId(`loa_approve_${user.id}`)
        .setLabel('Approve')
        .setStyle(ButtonStyle.Success);

    const denyButton = new ButtonBuilder()
        .setCustomId(`loa_deny_${user.id}`)
        .setLabel('Deny')
        .setStyle(ButtonStyle.Danger);

    const row = new ActionRowBuilder()
        .addComponents(approveButton, denyButton);

    try {
        const loaChannel = await client.channels.fetch(config.loaRequestChannelId);
        const message = await loaChannel.send({ embeds: [embed], components: [row] });

        activeLoaRequests.set(user.id, {
            messageId: message.id,
            userId: user.id,
            startingDate: startingDate,
            endDate: endDate,
            reason: reason
        });

        await interaction.reply({ content: 'Your LOA request has been submitted!', ephemeral: true });
    } catch (error) {
        console.error('Error submitting LOA request:', error);
        await interaction.reply({ content: 'Failed to submit LOA request. Please check the bot configuration.', ephemeral: true });
    }
}

async function handleStaffInfo(interaction) {
    const name = interaction.options.getString('name');
    const nickname = interaction.options.getString('nickname');
    const position = interaction.options.getString('position');

    const embed = new EmbedBuilder()
        .setColor('#3498DB')
        .setTitle('๐Ÿ‘ค Staff Information')
        .addFields(
            { name: 'Name', value: name, inline: true },
            { name: 'Nickname', value: nickname, inline: true },
            { name: 'Position', value: position, inline: true }
        )
        .setTimestamp();

    await interaction.reply({ embeds: [embed] });
}

async function handleButton(interaction) {
    const customId = interaction.customId;

    if (customId.startsWith('loa_approve_')) {
        await handleLoaApprove(interaction);
    } else if (customId.startsWith('loa_deny_')) {
        await handleLoaDeny(interaction);
    }
}

async function handleLoaApprove(interaction) {
    const member = interaction.member;
    
    if (!member.roles.cache.has(config.adminRoleId)) {
        await interaction.reply({ content: 'You do not have permission to approve LOA requests. Only admins can approve or deny LOAs.', ephemeral: true });
        return;
    }

    const userId = interaction.customId.split('_')[2];
    const loaRequest = activeLoaRequests.get(userId);

    if (!loaRequest) {
        await interaction.reply({ content: 'LOA request not found.', ephemeral: true });
        return;
    }

    try {
        const guild = interaction.guild;
        const targetMember = await guild.members.fetch(userId);
        const loaRole = await guild.roles.fetch(config.loaRoleId);

        if (loaRole) {
            await targetMember.roles.add(loaRole);
        }

        const userEmbed = new EmbedBuilder()
            .setColor('#00FF00')
            .setTitle('โœ… LOA Request Approved')