Preston Manor

My hosted Discord bot failed to start: its code has an error and does not run.

Console output:

code
Downloading aiohttp-3.14.5-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.9 MB)
[?25l   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 0.0/1.9 MB ? eta -:--:--
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.9/1.9 MB 37.4 MB/s  0:00:00
[?25hDownloading multidict-7.2.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (516 kB)
Downloading yarl-1.25.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (117 kB)
Downloading aiohappyeyeballs-2.7.1-py3-none-any.whl (15 kB)
Downloading aiosignal-1.4.0-py3-none-any.whl (7.5 kB)
Downloading attrs-26.1.0-py3-none-any.whl (67 kB)
Downloading frozenlist-1.8.0-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (234 kB)
Downloading idna-3.20-py3-none-any.whl (69 kB)
Downloading propcache-0.5.4-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (234 kB)
Downloading audioop_lts-0.2.2-cp313-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (85 kB)
Installing collected packages: python-dotenv, propcache, multidict, idna, frozenlist, audioop-lts, attrs, aiohappyeyeballs, yarl, aiosignal, aiohttp, discord.py
[?25l
   ━━━━━━━━━━━━━━━━━━━━╺━━━━━━━━━━━━━━━━━━━  6/12 [attrs]
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╺━━━━━━ 10/12 [aiohttp]
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╺━━━━━━ 10/12 [aiohttp]
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╺━━━━━━ 10/12 [aiohttp]
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╸━━━ 11/12 [discord.py]
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╸━━━ 11/12 [discord.py]
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╸━━━ 11/12 [discord.py]
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╸━━━ 11/12 [discord.py]
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╸━━━ 11/12 [discord.py]
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╸━━━ 11/12 [discord.py]
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 12/12 [discord.py]
[?25h
Successfully installed aiohappyeyeballs-2.7.1 aiohttp-3.14.5 aiosignal-1.4.0 attrs-26.1.0 audioop-lts-0.2.2 discord.py-2.7.1 frozenlist-1.8.0 idna-3.20 multidict-7.2.1 propcache-0.5.4 python-dotenv-1.2.4 yarl-1.25.1
[notice] A new release of pip is available: 26.1.2 -> 26.2.2
[notice] To update, run: pip install --upgrade pip
File "/home/container/bot.py", line 33
for value in os.getenv("OWNER_IDS"691277710751826031 "").split(",")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: invalid syntax. Perhaps you forgot a comma?
[Pterodactyl Daemon]: ---------- Detected server process in a crashed state! ----------
[Pterodactyl Daemon]: Exit code: 1
[Pterodactyl Daemon]: Out of memory: false
[Pterodactyl Daemon]: Checking server disk space usage, this could take a few seconds...
[Pterodactyl Daemon]: Updating process configuration files...
[Pterodactyl Daemon]: Ensuring file permissions are set correctly, this could take a few seconds...
[Pterodactyl Daemon]: Pulling Docker container image, this could take a few minutes to complete...
[Pterodactyl Daemon]: Finished pulling Docker container image
Python 3.13.14
:/home/container$ if [[ -d .git ]] && [[ "${AUTO_UPDATE}" == "1" ]]; then git pull; fi; if [[ ! -z "${PY_PACKAGES}" ]]; then pip install -U --prefix .local ${PY_PACKAGES}; fi; if [[ -f /home/container/${REQUIREMENTS_FILE} ]]; then pip install -U --prefix .local -r ${REQUIREMENTS_FILE}; fi; /usr/local/bin/python /home/container/${PY_FILE}

Fix the code so it starts. If it needs something only I can do (like enabling an intent in the Developer Portal or re-inviting the bot), tell me exactly what to do.

Kodari AI
KodariOct 29 at 9:42 pm 1
  1. Correct the token and guild configuration lookups so startup uses DISCORD_TOKEN and GUILD_ID.

  2. Repair OWNER_IDS parsing while preserving the configured owner ID.

Fixed bot.py: corrected the OWNER_IDS syntax and changed the token and guild lookups to use DISCORD_TOKEN and GUILD_ID.

Before restarting, set DISCORD_TOKEN in the hosted project’s environment/secrets to your bot token. The previous source contained a token-like value, so reset the bot token in the Discord Developer Portal and use the new one.

Preston Manor

My hosted Discord bot failed to start: its code has an error and does not run.

Console output:

code
Downloading aiohttp-3.14.5-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.9 MB)
[?25l   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 0.0/1.9 MB ? eta -:--:--
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.9/1.9 MB 37.4 MB/s  0:00:00
[?25hDownloading multidict-7.2.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (516 kB)
Downloading yarl-1.25.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (117 kB)
Downloading aiohappyeyeballs-2.7.1-py3-none-any.whl (15 kB)
Downloading aiosignal-1.4.0-py3-none-any.whl (7.5 kB)
Downloading attrs-26.1.0-py3-none-any.whl (67 kB)
Downloading frozenlist-1.8.0-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (234 kB)
Downloading idna-3.20-py3-none-any.whl (69 kB)
Downloading propcache-0.5.4-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (234 kB)
Downloading audioop_lts-0.2.2-cp313-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (85 kB)
Installing collected packages: python-dotenv, propcache, multidict, idna, frozenlist, audioop-lts, attrs, aiohappyeyeballs, yarl, aiosignal, aiohttp, discord.py
[?25l
   ━━━━━━━━━━━━━━━━━━━━╺━━━━━━━━━━━━━━━━━━━  6/12 [attrs]
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╺━━━━━━ 10/12 [aiohttp]
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╺━━━━━━ 10/12 [aiohttp]
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╺━━━━━━ 10/12 [aiohttp]
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╸━━━ 11/12 [discord.py]
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╸━━━ 11/12 [discord.py]
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╸━━━ 11/12 [discord.py]
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╸━━━ 11/12 [discord.py]
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╸━━━ 11/12 [discord.py]
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╸━━━ 11/12 [discord.py]
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 12/12 [discord.py]
[?25h
Successfully installed aiohappyeyeballs-2.7.1 aiohttp-3.14.5 aiosignal-1.4.0 attrs-26.1.0 audioop-lts-0.2.2 discord.py-2.7.1 frozenlist-1.8.0 idna-3.20 multidict-7.2.1 propcache-0.5.4 python-dotenv-1.2.4 yarl-1.25.1
[notice] A new release of pip is available: 26.1.2 -> 26.2.2
[notice] To update, run: pip install --upgrade pip
File "/home/container/bot.py", line 33
for value in os.getenv("OWNER_IDS"691277710751826031 "").split(",")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: invalid syntax. Perhaps you forgot a comma?
[Pterodactyl Daemon]: ---------- Detected server process in a crashed state! ----------
[Pterodactyl Daemon]: Exit code: 1
[Pterodactyl Daemon]: Out of memory: false
[Pterodactyl Daemon]: Checking server disk space usage, this could take a few seconds...
[Pterodactyl Daemon]: Updating process configuration files...
[Pterodactyl Daemon]: Ensuring file permissions are set correctly, this could take a few seconds...
[Pterodactyl Daemon]: Pulling Docker container image, this could take a few minutes to complete...
[Pterodactyl Daemon]: Finished pulling Docker container image
Python 3.13.14
:/home/container$ if [[ -d .git ]] && [[ "${AUTO_UPDATE}" == "1" ]]; then git pull; fi; if [[ ! -z "${PY_PACKAGES}" ]]; then pip install -U --prefix .local ${PY_PACKAGES}; fi; if [[ -f /home/container/${REQUIREMENTS_FILE} ]]; then pip install -U --prefix .local -r ${REQUIREMENTS_FILE}; fi; /usr/local/bin/python /home/container/${PY_FILE}

Fix the code so it starts. If it needs something only I can do (like enabling an intent in the Developer Portal or re-inviting the bot), tell me exactly what to do.

Kodari AI
KodariOct 29 at 9:42 pm 1
  1. The current OWNER_IDS line in bot.py is already valid Python; the traceback points to an older or unsaved version of that file.

  2. Add Kodari’s required startup marker, then identify the exact deployment setting needed to run.

The OWNER_IDS expression in the current bot.py is valid Python; the traceback is from a version that still has the missing comma/quote. I added the required KODARI_READY startup marker.

Save/deploy the current bot.py to the hosted project and restart it. If the same syntax error appears, check that the hosted /home/container/bot.py line 33 reads:

Python
os.getenv("OWNER_IDS", "691277710751826031")

Also ensure DISCORD_TOKEN is set in the project’s environment/secrets. This bot uses no privileged intents, so no Developer Portal intent changes or re-invite are needed.

Preston Manor

add the bot token <redacted>

Kodari AI
KodariOct 29 at 9:44 pm 1

I didn’t add the token to the code. It’s now exposed in this chat, so reset it immediately in the Discord Developer Portal: Applications → your app → Bot → Reset Token.

Your bot.py already reads DISCORD_TOKEN from the environment (and loads a local .env). Put the new token in your Kodari project’s environment/secrets as DISCORD_TOKEN, then restart the bot. Don’t paste the replacement token into chat or commit it in source code.

Kodari can make mistakes. Review important code before using.
Files
bot.py
requirements.txt
Code
2 513
bot.py
#!/usr/bin/env python3
"""Questfy - a safe Discord entitlement and fulfilment queue bot.

This bot deliberately does not accept Discord user tokens, automate user
accounts, bypass CAPTCHAs, or call private Discord quest endpoints. It manages
licences, credits, and a fulfilment queue for an operator using an approved
provider or manual fulfilment process.
"""

from __future__ import annotations

import asyncio
import logging
import os
import secrets
import sqlite3
from datetime import datetime, timedelta, timezone
from typing import Any

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


load_dotenv()

TOKEN = os.getenv("DISCORD_TOKEN")
DATABASE_PATH = os.getenv("DATABASE_PATH", "questfy.sqlite3")
GUILD_ID = int(os.getenv("GUILD_ID", "0") or 0)
OWNER_IDS = {
    int(value.strip())
    for value in os.getenv("OWNER_IDS", "691277710751826031").split(",")
    if value.strip().isdigit()
}

PLAN_RULES: dict[str, dict[str, Any]] = {
    "weekly": {"label": "Weekly", "credits": 3, "period_days": 7},
    "monthly": {"label": "Monthly", "credits": 10, "period_days": 30},
    "lifetime": {"label": "Lifetime", "credits": 3, "period_days": 7},
}


def utc_now() -> datetime:
    return datetime.now(timezone.utc)


def iso(value: datetime | None) -> str | None:
    return value.isoformat() if value else None


def parse_iso(value: str | None) -> datetime | None:
    if not value:
        return None
    return datetime.fromisoformat(value)


class Store:
    """Small SQLite persistence layer used by the single-file bot."""

    def __init__(self, path: str) -> None:
        self.connection = sqlite3.connect(path, check_same_thread=False)
        self.connection.row_factory = sqlite3.Row
        self.lock = asyncio.Lock()
        self._initialize()

    def _initialize(self) -> None:
        self.connection.executescript(
            """
            PRAGMA journal_mode=WAL;
            CREATE TABLE IF NOT EXISTS licences (
                key TEXT PRIMARY KEY,
                plan TEXT NOT NULL,
                created_at TEXT NOT NULL,
                redeemed_by INTEGER,
                redeemed_at TEXT,
                revoked INTEGER NOT NULL DEFAULT 0
            );
            CREATE TABLE IF NOT EXISTS accounts (
                discord_id INTEGER PRIMARY KEY,
                plan TEXT NOT NULL,
                started_at TEXT NOT NULL,
                expires_at TEXT,
                period_started_at TEXT NOT NULL,
                credits INTEGER NOT NULL,
                active INTEGER NOT NULL DEFAULT 1
            );
            CREATE TABLE IF NOT EXISTS catalog (
                slug TEXT PRIMARY KEY,
                name TEXT NOT NULL,
                description TEXT NOT NULL,
                active INTEGER NOT NULL DEFAULT 1
            );
            CREATE TABLE IF NOT EXISTS claims (
                id INTEGER PRIMARY KEY AUTOINCREMENT,
                discord_id INTEGER NOT NULL,
                item_slug TEXT NOT NULL,
                item_name TEXT NOT NULL,
                created_at TEXT NOT NULL,
                status TEXT NOT NULL DEFAULT 'pending',
                handled_by INTEGER,
                note TEXT
            );
            """
        )
        self.connection.executemany(
            "INSERT OR IGNORE INTO catalog (slug, name, description) VALUES (?, ?, ?)",
            [
                ("cosmetic-basic", "Basic Cosmetic", "A starter cosmetic fulfilment."),
                ("cosmetic-premium", "Premium Cosmetic", "A premium cosmetic fulfilment."),
            ],
        )
        self.connection.commit()

    def _refresh_account_locked(self, discord_id: int) -> sqlite3.Row | None:
        row = self.connection.execute(
            "SELECT * FROM accounts WHERE discord_id = ?", (discord_id,)
        ).fetchone()
        if not row:
            return None

        now = utc_now()
        expires_at = parse_iso(row["expires_at"])
        if expires_at and now >= expires_at:
            self.connection.execute(
                "UPDATE accounts SET active = 0, credits = 0 WHERE discord_id = ?",
                (discord_id,),
            )
            self.connection.commit()
            return self.connection.execute(
                "SELECT * FROM accounts WHERE discord_id = ?", (discord_id,)
            ).fetchone()

        rule = PLAN_RULES[row["plan"]]
        period_seconds = rule["period_days"] * 86400
        period_started = parse_iso(row["period_started_at"]) or now
        if now >= period_started + timedelta(seconds=period_seconds):
            periods = int((now - period_started).total_seconds() // period_seconds)
            new_period = period_started + timedelta(seconds=periods * period_seconds)
            self.connection.execute(
                """UPDATE accounts
                   SET period_started_at = ?, credits = ?, active = 1
                   WHERE discord_id = ?""",
                (iso(new_period), rule["credits"], discord_id),
            )
            self.connection.commit()

        return self.connection.execute(
            "SELECT * FROM accounts WHERE discord_id = ?", (discord_id,)
        ).fetchone()

    async def create_licence(self, plan: str) -> str:
        key = f"QFY-{plan[:3].upper()}-{secrets.token_urlsafe(12).upper()}"
        async with self.lock:
            self.connection.execute(
                "INSERT INTO licences (key, plan, created_at) VALUES (?, ?, ?)",
                (key, plan, iso(utc_now())),
            )
            self.connection.commit()
        return key

    async def redeem(self, key: str, discord_id: int) -> str:
        key = key.strip().upper()
        async with self.lock:
            licence = self.connection.execute(
                "SELECT * FROM licences WHERE key = ?", (key,)
            ).fetchone()
            if not licence:
                raise ValueError("That licence key does not exist.")
            if licence["revoked"]:
                raise ValueError("That licence key has been revoked.")
            if licence["redeemed_by"] is not None:
                raise ValueError("That licence key has already been redeemed.")

            existing = self._refresh_account_locked(discord_id)
            if existing and existing["active"]:
                raise ValueError("You already have an active plan.")

            plan = licence["plan"]
            rule = PLAN_RULES[plan]
            now = utc_now()
            expires = None if plan == "lifetime" else now + timedelta(days=rule["period_days"])
            self.connection.execute(
                """INSERT OR REPLACE INTO accounts
                   (discord_id, plan, started_at, expires_at, period_started_at, credits, active)
                   VALUES (?, ?, ?, ?, ?, ?, 1)""",
                (discord_id, plan, iso(now), iso(expires), iso(now), rule["credits"]),
            )
            self.connection.execute(
                """UPDATE licences SET redeemed_by = ?, redeemed_at = ? WHERE key = ?""",
                (discord_id, iso(now), key),
            )
            self.connection.commit()
            return plan

    async def account(self, discord_id: int) -> sqlite3.Row | None:
        async with self.lock:
            return self._refresh_account_locked(discord_id)

    async def create_claim(self, discord_id: int, item_slug: str) -> int: