ramoska

"Create a Discord duty management bot with a modern green embed panel like the image. The panel should have four buttons: 🟒 Start Duty, πŸ”΄ End Duty, ⚫ Exit Without Saving, πŸ”΅ View Stats. When a user starts duty, save the start time. When they end duty, calculate the total duty time and save it. Show the list of users currently on duty in the panel and automatically update it. Use Discord slash commands and buttons."

Kodari AI
KodariJul 2 at 10:50 pm 1

I’ll create a Discord duty management bot with a green embed panel, four buttons, persistent storage, and auto-updating duty list.

DutyManagerBot
A Discord duty management bot with an interactive green embed panel. Features four buttons for duty control: Start Duty, End Duty, Exit Without Saving, and View Stats. Tracks duty start times, calculates session durations, and saves total accumulated time per user. Displays a live-updating list of users currently on duty with elapsed time indicators.

Project structure:

  • bot.py β€” Entry point with !duty / !panel command, on_ready handler that re-attaches the persistent view after restart

  • duty_view.py β€” The green embed panel with 4 interactive buttons and a static build_embed() method that renders the live on-duty user list

  • data_manager.py β€” JSON file persistence for duty sessions (start times, total seconds, completed sessions) and the single panel message reference

How it works:

  1. Run !duty in any channel β€” sends a green embed panel with the 4 buttons

  2. 🟒 Start Duty β€” saves the user’s start timestamp, adds them to the panel’s on-duty list

  3. πŸ”΄ End Duty β€” calculates elapsed time, adds it to the user’s total saved duration, increments completed sessions

  4. ⚫ Exit Without Saving β€” discards the current session (no time added to total)

  5. πŸ”΅ View Stats β€” sends an ephemeral embed with total duty time, completed sessions, and current session status

  6. The panel auto-updates after every button press showing who’s on duty and for how long

  7. Survives bot restarts β€” panel re-attaches to the same message and refreshes with current data

Kodari can make mistakes. Review important code before using.
Files
bot.py
data_manager.py
duty_view.py
requirements.txt
Code
4 352
bot.py
import discord
from discord.ext import commands
import os
from dotenv import load_dotenv

from data_manager import get_panel_info, save_panel_info
from duty_view import DutyView

load_dotenv()

TOKEN = os.getenv("DISCORD_TOKEN")
if not TOKEN:
    raise ValueError("DISCORD_TOKEN not found in .env file")

intents = discord.Intents.default()
intents.message_content = True

bot = commands.Bot(command_prefix="!", intents=intents)


@bot.event
async def on_ready():
    print(f"Logged in as {bot.user} (ID: {bot.user.id})")
    print(f"  Servers: {len(bot.guilds)}")
    print(f"  Latency: {round(bot.latency * 1000)}ms")

    bot.add_view(DutyView())

    panel_info = get_panel_info()
    if panel_info.get("channel_id") and panel_info.get("message_id"):
        channel = bot.get_channel(panel_info["channel_id"])
        if channel:
            try:
                message = await channel.fetch_message(panel_info["message_id"])
                embed = DutyView.build_embed()
                await message.edit(embed=embed, view=DutyView())
                print(f"  Updated existing duty panel in #{channel.name}")
            except (discord.NotFound, discord.Forbidden):
                print("  Previous panel message not found, will create new one on command")


@bot.command(name="duty", aliases=["panel"])
async def duty_panel(ctx: commands.Context):
    """Display the duty management panel with interactive buttons."""
    await ctx.message.delete()

    panel_info = get_panel_info()

    if panel_info.get("channel_id") and panel_info.get("message_id"):
        channel = bot.get_channel(panel_info["channel_id"])
        if channel:
            try:
                message = await channel.fetch_message(panel_info["message_id"])
                embed = DutyView.build_embed()
                await message.edit(embed=embed, view=DutyView())
                confirm = await ctx.send(
                    f"Duty panel updated in {channel.mention}", delete_after=5
                )
                return
            except (discord.NotFound, discord.Forbidden):
                pass

    embed = DutyView.build_embed()
    message = await ctx.send(embed=embed, view=DutyView())
    save_panel_info(message.channel.id, message.id)


if __name__ == "__main__":
    bot.run(TOKEN)