API Reference

API Reference

Module Structure

Main Modules

main.py

Entry point and core bot functionality.

Key Functions:

Global Variables:

chatgpt.py

ChatGPT integration and conversation management.

Key Functions:

Classes:

fishing_game.py

Complete fishing game implementation.

Key Functions:

Global Variables:

games.py

Mini-games implementation and registration.

Key Functions:

Commands Registered:

Databases:

casino.py

Casino economy and games (Slots, Hi‑Lo, Roulette) with a chips ledger.

Key Functions / Commands:

Internals:

Databases:

Database Schemas

conversations.db

conversations table:

CREATE TABLE conversations (
    thread_id TEXT PRIMARY KEY,
    messages TEXT NOT NULL,
    last_updated DATETIME NOT NULL
);

thread_meta table:

CREATE TABLE thread_meta (
    thread_id TEXT PRIMARY KEY,
    creator_id TEXT NOT NULL,
    created_at DATETIME NOT NULL
);

fishing_game.db

catches table:

CREATE TABLE catches (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    user_id TEXT,
    user_name TEXT,
    catch_type TEXT, -- 'fish' or 'user'
    catch_name TEXT,
    weight REAL,
    points INTEGER,
    timestamp DATETIME
);

games_stats.db

rps_stats table:

CREATE TABLE rps_stats (
  guild_id TEXT NOT NULL,
  user_id TEXT NOT NULL,
  wins INTEGER NOT NULL DEFAULT 0,
  losses INTEGER NOT NULL DEFAULT 0,
  draws INTEGER NOT NULL DEFAULT 0,
  last_played DATETIME NOT NULL,
  PRIMARY KEY (guild_id, user_id)
);
CREATE INDEX idx_rps_stats_guild ON rps_stats(guild_id);

casino_chips table:

CREATE TABLE casino_chips (
  guild_id TEXT NOT NULL,
  user_id TEXT NOT NULL,
  balance INTEGER NOT NULL DEFAULT 0,
  last_updated DATETIME NOT NULL,
  last_faucet DATETIME,
  PRIMARY KEY (guild_id, user_id)
);

casino_ledger table:

CREATE TABLE casino_ledger (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  guild_id TEXT NOT NULL,
  user_id TEXT NOT NULL,
  game TEXT NOT NULL,
  delta INTEGER NOT NULL,
  balance_after INTEGER NOT NULL,
  ts DATETIME NOT NULL,
  meta TEXT
);

slots_rounds table:

CREATE TABLE slots_rounds (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  guild_id TEXT NOT NULL,
  user_id TEXT NOT NULL,
  bet INTEGER NOT NULL,
  payout INTEGER NOT NULL,
  symbols TEXT NOT NULL,
  ts DATETIME NOT NULL
);

roulette_rounds table:

CREATE TABLE roulette_rounds (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  guild_id TEXT NOT NULL,
  user_id TEXT NOT NULL,
  bet INTEGER NOT NULL,
  payout INTEGER NOT NULL,
  selection TEXT NOT NULL,
  result_number INTEGER NOT NULL,
  result_color TEXT NOT NULL,
  ts DATETIME NOT NULL
);

Configuration Schemas

myconfig.json

{
  required_role: string | null,
  token_usage_display: boolean,
  chat_thread_retention_days: number,
  max_tokens: {
    [command: string]: number
  },
  prompts: {
    [command: string]: {
      [variant: string]: string
    }
  }
}

my_fishing_game_config.json

{
  member_catch_ratio: number,
  cooldown_seconds: number,
  fish: Array<{
    name: string,
    min_size_cm: number,
    max_size_cm: number,
    min_weight_kg: number,
    max_weight_kg: number
  }>
}

OpenAI Integration

Chat Completion

response = client.chat.completions.create(
    model="gpt-4",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Hello!"}
    ],
    max_tokens=150,
    temperature=0.8
)

Image Generation

response = client.images.generate(
    prompt="A sunset over mountains",
    n=1,
    size="1024x1024"
)

Discord.py Events

Used Events

Custom Events

Error Handling

Standard Pattern

try:
    # Operation
except SpecificException as e:
    print(f"Specific error: {e}")
    # Handle gracefully
except Exception as e:
    print(f"Unexpected error: {e}")
    # Fallback behavior

Database Connections

with get_db_connection() as conn:
    c = conn.cursor()
    # Database operations
    conn.commit()

Async Patterns

Command Structure

@bot.command(help="Description", aliases=["alt"])
async def command_name(ctx, *, parameter: str = None):
    async with ctx.typing():
        # Long operation
    await ctx.send(response)

Thread Safety

Extension Points

Adding Commands

  1. Add to appropriate module
  2. Use @bot.command() decorator
  3. Include help text
  4. Handle errors gracefully

Adding Fish Species

  1. Add image to assets folder
  2. Update configuration
  3. No code changes needed

Custom Prompts

  1. Modify prompts in config
  2. Use placeholders: {topic}
  3. Test thoroughly

Performance Considerations

Database

Discord API

OpenAI API


Generated from repository docs. Last build: 2025-09-12 11:03 UTC