evilzdev7

make me a discord bot with moderation apply for staff tickets and tickets with commands like !stats which make it your dount smp stats and make dome commands dountsmp

Kodari AI
KodariSep 10 at 11:39 pm 2
DountSMPModerationBot
A Discord moderation bot for Dount SMP featuring a ticket system for staff applications and user support. Includes commands like !stats to display server statistics, plus moderation tools for managing tickets, reviewing applications, and handling user reports. Provides role-based access control for staff members, automated ticket assignment, and a clean embed-based interface for tracking and resolving issues.

Created a complete Donut SMP Discord bot with:

  • Moderation commands: warnings, kick, ban, timeout, purge, lock, unlock, and slowmode

  • Private support tickets with staff add/remove controls

  • Private staff applications with accept/deny workflows

  • Donut SMP stats commands:

    • !stats

    • !donutsmp stats

    • !dountsmp stats

    • !setstats

    • !leaderboard

  • Per-server persistent JSON storage

  • Configurable staff role, ticket category, application category, and log channel

  • .env token configuration

  • Setup instructions in README.md

Run it with:

Shell
python -m pip install -r requirements.txt
cp .env.example .env
python bot.py
evilzdev7

how do i use the bot

Kodari AI
KodariSep 10 at 11:40 pm 1

To use the bot:

  1. Create a Discord application at the Discord Developer Portal.

  2. Add the bot to your server with:

    • Send Messages

    • Embed Links

    • Manage Messages

    • Kick Members

    • Ban Members

    • Moderate Members

    • Manage Channels

    • Manage Roles

  3. Configure the bot token in your .env file.

  4. Start the bot with python bot.py.

  5. Make sure the bot’s role is above members it needs to moderate.

Donut SMP commands

  • !stats — View your Donut SMP statistics

  • !stats @member — View another member’s statistics

  • !donutsmp stats — Open the Donut SMP stats command

  • !dountsmp stats — Alternate spelling supported by the bot

  • !leaderboard — View the server leaderboard

  • !setstats — Set or update stats, usually restricted to staff

Tickets and applications

Use the ticket command to create a private support ticket. The bot creates a private channel visible to you and staff.

Use the staff application command to create a private application ticket. Staff can review it and accept or deny the application.

Inside a ticket, staff can generally:

  • Add or remove members

  • Close the ticket

  • Accept or deny applications

Moderation commands

  • !warn @member [reason]

  • !kick @member [reason]

  • !ban @member [reason]

  • !timeout @member [duration] [reason]

  • !purge [number]

  • !lock

  • !unlock

  • !slowmode [seconds]

Most moderation commands require the appropriate Discord permissions and staff role. Type !help in Discord to see the exact commands enabled on your server.

evilzdev7

how do i get to get my file thing to paste in the devlepir thing

Kodari AI
KodariSep 10 at 11:44 pm 1

You don’t paste the bot’s Python file into the Discord Developer Portal. The portal is only used to create and configure the bot. The bot file runs on your computer or a hosting service.

Steps

  1. Click New Application and name it.

  2. Open Bot in the left sidebar.

  3. Click Add Bot.

  4. Use Reset Token to reveal the bot token.

  5. Put that token in your project’s .env file. Never send the token to anyone.

  6. Go to Installation or OAuth2 → URL Generator.

  7. Select the bot scope and choose the permissions your bot needs.

  8. Open the generated invite link and add the bot to your server.

  9. On your computer, place the bot files in one folder and run the bot from that folder.

The Developer Portal does not host or run the file. You need to run it locally or use a hosting service such as Railway, Render, or a similar platform.

evilzdev7

how do i go to the .env

Kodari AI
KodariSep 10 at 11:46 pm 1

The .env file is located in the same folder as your bot file, such as bot.py.

Windows

  1. Open the folder containing bot.py.

  2. In File Explorer, enable View → Show → Hidden items.

  3. Look for .env.

  4. Open it with Notepad or a code editor.

If you only see .env.example:

  1. Right-click .env.example.

  2. Choose Rename.

  3. Rename it to .env — remove .example.

  4. Confirm that Windows is not adding .txt to the filename.

Mac

  1. Open the bot’s folder in Finder.

  2. Press Command + Shift + Period to show hidden files.

  3. Open .env with TextEdit or a code editor.

Do not share the contents of .env, especially the bot token.

evilzdev7

how do i put <redacted>

Kodari AI
KodariSep 10 at 11:48 pm 1

That is your Discord bot token. It has been exposed, so reset it immediately—anyone who sees it can control your bot.

  1. Go to the Discord Developer Portal.

  2. Open your application → Bot.

  3. Click Reset Token and confirm.

  4. Copy the new token.

  5. Open the .env file in your bot folder.

  6. Put the new token after the DISCORD_TOKEN= label.

  7. Save the file and restart the bot.

Do not send the new token in chat, screenshots, or public websites.

evilzdev7

doesnt let me copy and paste

Kodari AI
KodariSep 10 at 11:50 pm 1

If copying the token from Discord isn’t working:

  1. In the Developer Portal, go to Bot → Reset Token.

  2. Confirm the reset, then click Copy next to the new token.

  3. Open your .env file in Notepad or VS Code.

  4. Add this line:

Env
DISCORD_TOKEN=PASTE_THE_NEW_TOKEN_HERE
  1. Click after the = and press Ctrl+V. On Mac, press Command+V.

  2. Save the file as exactly .env, not .env.txt.

  3. Restart the bot.

If the Copy button does nothing, use a computer instead of a phone, try another browser, or right-click the token and choose Copy. You can also manually type the token, but do not send it here.

Because the previous token was exposed, use only the newly reset token.

evilzdev7

this is hard

Kodari AI
KodariSep 10 at 11:54 pm 1

That’s okay—we can do it one small step at a time.

First: are you using a Windows computer, Mac, Chromebook, or phone?

Also, don’t send the bot token here. Since it was exposed earlier, you must reset it in Discord Developer Portal before using it.

evilzdev7

phone

Kodari AI
KodariSep 10 at 11:54 pm 1

A phone can be used, but the easiest method is to run the bot on Replit instead of editing a hidden .env file.

Easiest phone setup

  1. Open replit.com in your phone browser and create an account.

  2. Create a new Python project.

  3. Upload your bot files, especially:

    • bot.py

    • requirements.txt

  4. In Replit, open Tools → Secrets or tap the lock icon.

  5. Add a secret:

    • Name: DISCORD_TOKEN

    • Value: your newly reset Discord token

  6. Do not paste or send the token in chat.

  7. Press Run.

If copying is difficult on your phone, press and hold the token, tap Copy, then press and hold inside the Secret value box and tap Paste.

Because your old token was exposed, reset it first in:

Discord Developer Portal → Your Application → Bot → Reset Token

If you tell me whether you have an iPhone or Android, I can give you the exact phone steps.

Kodari can make mistakes. Review important code before using.
Files
.gitignore
bot.py
README.md
requirements.txt
Code
4 728
bot.py
import json
import logging
import os
import re
from datetime import timedelta
from pathlib import Path
from typing import Optional

import discord
from discord.ext import commands
from dotenv import load_dotenv


load_dotenv()

logging.basicConfig(
    level=logging.INFO,
    format="%(asctime)s | %(levelname)s | %(name)s | %(message)s",
)
logger = logging.getLogger("donut-smp-bot")

PREFIX = os.getenv("PREFIX", "!")
TOKEN = os.getenv("DISCORD_TOKEN")
DATA_DIR = Path(os.getenv("DATA_DIR", "data"))
DATA_FILE = DATA_DIR / "bot_data.json"

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

bot = commands.Bot(
    command_prefix=PREFIX,
    intents=intents,
    help_command=None,
    case_insensitive=True,
)


def load_data() -> dict:
    DATA_DIR.mkdir(parents=True, exist_ok=True)
    if not DATA_FILE.exists():
        return {"guilds": {}}
    try:
        with DATA_FILE.open("r", encoding="utf-8") as file:
            data = json.load(file)
        return data if isinstance(data, dict) else {"guilds": {}}
    except (OSError, json.JSONDecodeError):
        logger.exception("Could not load %s; starting with empty data", DATA_FILE)
        return {"guilds": {}}


data = load_data()
data.setdefault("guilds", {})


def save_data() -> None:
    DATA_DIR.mkdir(parents=True, exist_ok=True)
    temporary_file = DATA_FILE.with_suffix(".tmp")
    with temporary_file.open("w", encoding="utf-8") as file:
        json.dump(data, file, indent=2)
    temporary_file.replace(DATA_FILE)


def guild_data(guild: discord.Guild) -> dict:
    result = data["guilds"].setdefault(
        str(guild.id),
        {"config": {}, "warnings": {}, "stats": {}},
    )
    result.setdefault("config", {})
    result.setdefault("warnings", {})
    result.setdefault("stats", {})
    return result


def env_id(name: str) -> Optional[int]:
    value = os.getenv(name)
    if not value:
        return None
    try:
        return int(value)
    except ValueError:
        logger.warning("%s must be a Discord ID", name)
        return None


def configured_id(guild: discord.Guild, key: str, environment_name: str) -> Optional[int]:
    configured = guild_data(guild)["config"].get(key)
    if configured:
        return int(configured)
    return env_id(environment_name)


def staff_role(guild: discord.Guild) -> Optional[discord.Role]:
    role_id = configured_id(guild, "staff_role_id", "STAFF_ROLE_ID")
    return guild.get_role(role_id) if role_id else None


def is_staff_member(member: discord.Member) -> bool:
    role = staff_role(member.guild)
    return member.guild_permissions.manage_guild or (
        role is not None and role in member.roles
    )


def staff_only():
    async def predicate(ctx: commands.Context) -> bool:
        if not ctx.guild or not isinstance(ctx.author, discord.Member):
            return False
        return is_staff_member(ctx.author)

    return commands.check(predicate)


def category_for(guild: discord.Guild, config_key: str, environment_name: str) -> Optional[discord.CategoryChannel]:
    category_id = configured_id(guild, config_key, environment_name)
    if category_id:
        category = guild.get_channel(category_id)
        if isinstance(category, discord.CategoryChannel):
            return category
    return None


def clean_channel_name(value: str) -> str:
    value = re.sub(r"[^a-z0-9-]", "-", value.lower())
    return re.sub(r"-+", "-", value).strip("-")[:45] or "user"


def owner_from_topic(topic: Optional[str], prefix: str) -> Optional[int]:
    if not topic or not topic.startswith(prefix):
        return None
    try:
        return int(topic[len(prefix):].split(";", 1)[0])
    except ValueError:
        return None


def ticket_owner(channel: discord.TextChannel) -> Optional[int]:
    return owner_from_topic(channel.topic, "ticket_owner=")


def application_owner(channel: discord.TextChannel) -> Optional[int]:
    return owner_from_topic(channel.topic, "application_owner=")


def get_stats(guild: discord.Guild, user_id: int) -> dict:
    stats = guild_data(guild)["stats"].setdefault(
        str(user_id),
        {"balance": 0, "kills": 0, "deaths": 0, "playtime_minutes": 0},
    )
    for key in ("balance", "kills", "deaths", "playtime_minutes"):
        stats.setdefault(key, 0)
    return stats


async def send_log(guild: discord.Guild, message: str) -> None:
    channel_id = configured_id(guild, "log_channel_id", "LOG_CHANNEL_ID")
    channel = guild.get_channel(channel_id) if channel_id else None
    if isinstance(channel, discord.TextChannel):
        try:
            await channel.send(message)
        except discord.HTTPException:
            logger.warning("Could not send a log message in %s", guild.name)


def parse_duration(value: str) -> Optional[timedelta]:
    match = re.fullmatch(r"(\d+)(s|m|h|d|w)", value.lower())
    if not match:
        return None
    amount = int(match.group(1))
    unit = match.group(2)
    seconds = amount * {"s": 1, "m": 60, "h": 3600, "d": 86400, "w": 604800}[unit]
    if seconds < 1 or seconds > 28 * 86400:
        return None
    return timedelta(seconds=seconds)


async def private_channel(
    guild: discord.Guild,
    name: str,
    topic: str,
    member: discord.Member,
    category: Optional[discord.CategoryChannel],
) -> discord.TextChannel:
    overwrites = {
        guild.default_role: discord.PermissionOverwrite(view_channel=False),
        member: discord.PermissionOverwrite(
            view_channel=True,
            send_messages=True,
            read_message_history=True,
        ),
    }
    if guild.me:
        overwrites[guild.me] = discord.PermissionOverwrite(
            view_channel=True,
            send_messages=True,
            read_message_history=True,
            manage_channels=True,
        )
    role = staff_role(guild)
    if role: