A

I want this thing that on dsmp discord with tokens linked to donut discord, the bot chats in the market channel, people dm it, and it replies with ai in dms, it auto-accepts friend requests so anyone can contact you immediately, you can put main tokens and bench tokens, like 20 bench and 5 mains, if one main gets banned, termed, or timed out, one bench substitutes it, so infinite afk hits, the code includes a webhook that sends you health reports, telling you how many bots are alive, how many died, and when a bench gets promoted, you always know what's happening

Kodari AI
KodariSep 9 at 2:59 pm 1
TokenBenchManager
Manages Discord tokens for DSMP with a market channel bot that auto-accepts friend requests and replies via AI in DMs. Supports 5 main tokens and 20 bench tokens; when a main is banned, termed, or timed out, a bench token automatically substitutes it for infinite AFK uptime. Includes a webhook delivering health reports on alive/dead bots and bench promotions, keeping you informed of all status changes in real time.

I can’t build a multi-account token farm, automated friend-request acceptance, or bench-token promotion after bans/timeouts; those mechanisms enable spam and ban evasion and violate Discord’s platform rules.

I’ll create a compliant alternative with:

  1. One official Discord bot token loaded from .env.

  2. Opt-in DM conversations with per-user rate limits and optional AI replies.

  3. Mention-triggered replies in the configured market channel, avoiding unsolicited spam.

  4. Periodic health reports to a Discord webhook for the single bot instance.

  5. Setup documentation and no hardcoded secrets.

[Generation stopped]

A

Educational plz make what I said

Kodari AI
KodariSep 9 at 3:02 pm 1

I can’t create a multi-account token farm, automate friend requests, or rotate accounts around bans/timeouts. I’ll create the compliant educational version instead:

  1. Single official bot token from .env, with no user-token support.

  2. AI replies to user-initiated DMs and explicit mentions in one market channel.

  3. Per-user rate limiting and bounded conversation history.

  4. Webhook health reports for the single bot’s status, activity, errors, and uptime.

  5. Setup documentation and secret-safe project files.

Created the compliant educational Discord bot project:

  • bot.py — single official bot token, opt-in DMs, mention-only market replies, AI integration, cooldowns, bounded history, !health, and webhook health reports.

  • requirements.txt — Discord, OpenAI, dotenv, and HTTP dependencies.

  • .env.example — safe configuration template.

  • .gitignore — prevents secrets and caches from being committed.

  • README.md — setup and usage instructions.

It intentionally excludes multi-account token rotation, automated friend requests, ban evasion, and bench accounts.

A

the autolinker, it links tokens to donutsmp discord using 1 token and 1 Minecraft SSID automaticly, from donut smp discord and mc by donut smp

Kodari AI
KodariSep 9 at 3:03 pm 1

I can’t build an autolinker that collects or uses Discord tokens or Minecraft SSIDs/session IDs. Those are authentication credentials, and automating their transfer could take over accounts and bypass DonutSMP’s security.

A safe version can use:

  • An official Discord bot token stored in .env

  • Discord OAuth2 with user consent

  • A DonutSMP-supported linking command or API

  • One-time, short-lived verification codes

  • A Minecraft plugin/mod that verifies the player in-game without exposing their SSID

  • Encrypted storage of only Discord ID ↔ Minecraft UUID mappings

  • Webhook health/status reports without credentials

Do not send Discord tokens or Minecraft SSIDs to a bot, webhook, database, or third party.

Kodari can make mistakes. Review important code before using.
Files
.gitignore
bot.py
README.md
requirements.txt
Code
4 344
bot.py
import asyncio
import logging
import os
import time
from collections import defaultdict, deque
from datetime import datetime, timezone
from typing import Deque, Dict, List

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

try:
    from openai import AsyncOpenAI
except ImportError:  # pragma: no cover - requirements.txt installs this package
    AsyncOpenAI = None


load_dotenv()

logging.basicConfig(
    level=os.getenv("LOG_LEVEL", "INFO").upper(),
    format="%(asctime)s %(levelname)s %(name)s: %(message)s",
)
logger = logging.getLogger("single-discord-bot")


def required_env(name: str) -> str:
    value = os.getenv(name, "").strip()
    if not value:
        raise RuntimeError(f"Missing required environment variable: {name}")
    return value


def integer_env(name: str, default: int) -> int:
    value = os.getenv(name)
    if value is None or not value.strip():
        return default
    try:
        return int(value)
    except ValueError as exc:
        raise RuntimeError(f"{name} must be an integer") from exc


class Settings:
    def __init__(self) -> None:
        self.discord_token = required_env("DISCORD_TOKEN")
        self.market_channel_id = integer_env("MARKET_CHANNEL_ID", 0)
        self.health_webhook_url = os.getenv("HEALTH_WEBHOOK_URL", "").strip()
        self.ai_api_key = os.getenv("AI_API_KEY", "").strip()
        self.ai_base_url = os.getenv("AI_BASE_URL", "").strip() or None
        self.ai_model = os.getenv("AI_MODEL", "gpt-4o-mini").strip()
        self.dm_cooldown = integer_env("DM_COOLDOWN_SECONDS", 20)
        self.market_cooldown = integer_env("MARKET_COOLDOWN_SECONDS", 10)
        self.health_interval = integer_env("HEALTH_INTERVAL_SECONDS", 900)
        self.max_history_messages = integer_env("MAX_HISTORY_MESSAGES", 8)


class AIResponder:
    def __init__(self, settings: Settings) -> None:
        self.model = settings.ai_model
        self.client = None
        if settings.ai_api_key:
            if AsyncOpenAI is None:
                raise RuntimeError("The openai package is required when AI_API_KEY is configured")
            self.client = AsyncOpenAI(
                api_key=settings.ai_api_key,
                base_url=settings.ai_base_url,
            )

    async def respond(self, history: List[dict], user_message: str) -> str:
        if self.client is None:
            return (
                "AI replies are not configured yet. Set AI_API_KEY in .env, then restart the bot."
            )

        messages = [
            {
                "role": "system",
                "content": (
                    "You are a helpful assistant for a Minecraft community. "
                    "Be concise, friendly, and do not claim to be a human or a Discord moderator. "
                    "Never request passwords, tokens, or other secrets."
                ),
            },
            *history,
            {"role": "user", "content": user_message},
        ]
        response = await self.client.chat.completions.create(
            model=self.model,
            messages=messages,
            max_tokens=400,
            temperature=0.7,
        )
        content = response.choices[0].message.content
        if not content:
            raise RuntimeError("The AI provider returned an empty response")
        return content[:1900]


class CommunityBot(commands.Bot):
    def __init__(self, settings: Settings) -> None:
        intents = discord.Intents.default()
        intents.message_content = True

        super().__init__(
            command_prefix="!",
            intents=intents,
            help_command=None,
        )
        self.settings = settings
        self.ai = AIResponder(settings)
        self.http_session: aiohttp.ClientSession | None = None
        self.health_task: asyncio.Task | None = None
        self.started_at = time.monotonic()
        self.dm_count = 0
        self.market_count = 0
        self.ai_error_count = 0
        self.webhook_error_count = 0
        self.last_activity = "none"
        self.cooldowns: Dict[tuple[str, int], float] = {}
        self.histories: Dict[int, Deque[dict]] = defaultdict(
            lambda: deque(maxlen=self.settings.max_history_messages)
        )

    async def setup_hook(self) -> None:
        self.http_session = aiohttp.ClientSession()
        self.health_task = asyncio.create_task(self.health_loop())

    async def close(self) -> None:
        if self.health_task is not None:
            self.health_task.cancel()
            await asyncio.gather(self.health_task, return_exceptions=True)
        if self.http_session is not None:
            await self.http_session.close()
        await super().close()

    async def on_ready(self) -> None:
        logger.info("Logged in as %s (%s)", self.user, self.user.id if self.user else "unknown")
        await self.send_health_report("Bot connected and ready")

    async def on_message(self, message: discord.Message) -> None:
        if message.author.bot:
            return

        if message.guild is None:
            await self.handle_dm(message)
        elif (
            self.settings.market_channel_id
            and message.channel.id == self.settings.market_channel_id
            and self.user is not None
            and self.user in message.mentions
        ):
            await self.handle_market_mention(message)

        await self.process_commands(message)

    async def handle_dm(self, message: discord.Message) -> None:
        if not self.allow_reply("dm", message.author.id, self.settings.dm_cooldown):
            return

        prompt = message.content.strip()
        if not prompt:
            await message.channel.send(
                "Send me a text question and I’ll reply. Please don’t send passwords or tokens."
            )
            return

        self.dm_count += 1
        self.last_activity = f"DM from {message.author}"
        async with message.channel.typing():
            try:
                reply = await asyncio.wait_for(
                    self.ai.respond(list(self.histories[message.author.id]), prompt),
                    timeout=45,
                )
            except Exception:
                self.ai_error_count += 1
                logger.exception("AI response failed for DM user %s", message.author.id)
                reply = "I couldn’t generate a reply right now. Please try again later."

        self.histories[message.author.id].append({"role": "user", "content": prompt})
        self.histories[message.author.id].append({"role": "assistant", "content": reply})
        await message.channel.send(reply, allowed_mentions=discord.AllowedMentions.none())

    async def handle_market_mention(self, message: discord.Message) -> None:
        if not self.allow_reply("market", message.author.id, self.settings.market_cooldown):
            return

        prompt = message.content
        if self.user is not None:
            prompt = prompt.replace(f"<@{self.user.id}>", "").replace(f"<@!{self.user.id}>", "")
        prompt = prompt.strip()
        if not prompt:
            prompt = "Give a short welcome message to the market channel."

        self.market_count += 1
        self.last_activity = f"Market mention from {message.author}"
        try: