Skip to content

Repository files navigation

DiscordBot
DiscordBot

Sponsor
Ko-fiDonate
PythonuvRuffLicense: MITRelease
issuesSonarCloud CoverageQuality Gate StatusCI/CD PipelineBuild Status

A simple Discord bot with multi-provider AI commands (OpenAI / Claude / Gemini) and server administration tools.
This bot serves as a starting point (template) for building other bots.

Table of Contents

Features

  • Multi-provider AI commands (OpenAI / Anthropic Claude / Google Gemini) with optional web search
  • Guild Wars 2 API integration (accounts, WvW, sessions, wiki)
  • Server administration and moderation tools
  • Custom commands, profanity filtering, and text-to-speech
  • Persistent embed pagination that survives bot restarts
  • PostgreSQL database with Alembic migrations
  • Docker deployment with automatic database migrations

Prerequisites

Installation

1. Clone the repository

git clone https://github.com/ddc/DiscordBot.git
cd DiscordBot

2. Configure environment variables

cp .env.example .env

Edit the .env file and set the required values:

# RequiredBOT_TOKEN=your_discord_bot_token
# Optional — any of the AI providers (you can configure one, two, or all three)BOT_OPENAI_API_KEY=your_openai_api_key
BOT_ANTHROPIC_API_KEY=your_anthropic_api_key
BOT_GEMINI_API_KEY=your_google_ai_studio_key
# DatabasePOSTGRESQL_HOST=postgres
POSTGRESQL_PORT=5432
POSTGRESQL_USER=postgres
POSTGRESQL_PASSWORD=postgres
POSTGRESQL_DATABASE=discordbot

See Configuration for all available options.

3. Start the bot

The bot expects an external PostgreSQL instance running on a Docker network named postgres_network. If you don't have one, you can start a local database using the included compose file:

docker compose -f docker-compose-localdb.yml up -d

Then start the bot:

sudo systemctl enable docker
docker compose up --build -d

This will:

  1. Build the Docker image
  2. Run database migrations automatically
  3. Start the bot

4. Verify the bot is running

docker-compose logs -f discordbot

For the full installation guide, see the Wiki.

Configuration

All configuration is done through environment variables in the .env file.

Bot Settings

VariableDefaultDescription
BOT_TOKENDiscord bot token (required)
BOT_PREFIX!Command prefix
BOT_EMBED_COLORgreenDefault embed color
BOT_EMBED_OWNER_COLORdark_purpleOwner command embed color
BOT_ALLOWED_DM_COMMANDSowner,about,gw2Commands allowed in DMs
BOT_BOT_REACTION_WORDSstupid,noobWords that trigger bot reactions
BOT_EXCLUSIVE_USERSRestrict bot to specific users (comma-separated IDs)
BOT_BG_ACTIVITY_TIMER0Background activity rotation timer (seconds, 0 = disabled)

AI Provider Settings

Configure any subset of the three providers — commands for unconfigured providers will return an error embed and the rest will still work.

VariableDefaultDescription
BOT_OPENAI_API_KEYOpenAI API key (powers gpt, gptweb)
BOT_OPENAI_MODELgpt-5.5OpenAI model name
BOT_ANTHROPIC_API_KEYAnthropic API key (powers claude, claudeweb)
BOT_ANTHROPIC_MODELclaude-opus-4-8Anthropic model name
BOT_GEMINI_API_KEYGoogle AI Studio key (powers gemini, geminiweb)
BOT_GEMINI_MODELgemini-flash-latestGemini model name (rolling-latest alias)

PostgreSQL Settings

VariableDefaultDescription
POSTGRESQL_HOSTpostgresDatabase host
POSTGRESQL_PORT5432Database port
POSTGRESQL_USERpostgresDatabase user
POSTGRESQL_PASSWORDpostgresDatabase password
POSTGRESQL_DATABASEdiscordbotDatabase name
POSTGRESQL_SCHEMApublicDatabase schema

Logging Settings

VariableDefaultDescription
LOG_LEVELINFOLog level
LOG_TIMEZONEUTCLog timezone
LOG_DIRECTORY/app/DiscordBotLog file directory
LOG_DAYS_TO_KEEP30Log retention in days

See .env.example for the complete list of configuration options including cooldowns, SSL, connection pooling, and retry settings.

Commands

AI / LLM Commands

Six commands across three providers. The *web variants enable the provider's built-in web search (OpenAI web_search, Anthropic web_search, Google Search grounding) for current/factual questions. The plain variants answer from training only — faster, cheaper, no live data.

All AI commands are channel-only (they cannot be invoked in DMs).

CommandProviderWeb search
gpt <message>OpenAIno
gptweb <message>OpenAIyes
claude <message>Anthropic Claudeno
claudeweb <message>Anthropic Claudeyes
gemini <message>Google Geminino
geminiweb <message>Google Geminiyes

Admin/Mod Commands

CommandDescription
admin botgame <new game>Change game that bot is playing

Config Commands

CommandDescription
admin config listList all bot configurations
admin config joinmessage [on, off]Toggle message when a user joins the server
admin config leavemessage [on, off]Toggle message when a user leaves the server
admin config servermessage [on, off]Toggle message when a server gets updated
admin config membermessage [on, off]Toggle message when someone updates profile
admin config blockinvisible [on, off]Block messages from invisible members
admin config botreactions [on, off]Toggle bot reactions to member words
admin config pfilter [on, off] <channel>Configure profanity filter per channel

Custom Commands

CommandDescription
admin cc add <command> <text>Add a new custom command
admin cc edit <command> <text>Edit an existing custom command
admin cc remove <command>Remove a custom command
admin cc removeallRemove all custom commands
admin cc listList all custom commands

Misc Commands

CommandDescription
aboutDisplay bot info
echo <message>Show your message again
pingTest latency
pepePost a random Pepe image
tts <message>Send text-to-speech as .mp3 to channel
serverinfoShow server information
userinfo <member>Show Discord user information
lmgtfy <search>Create a LMGTFY link
invitesList active invite links for the server

Dice Rolls Commands

CommandDescription
rollRoll a die (defaults to 100)
roll <size>Roll a die with specified size
roll resultsDisplay all dice rolls from the server
roll resetDelete all dice rolls (admin only)

Bot Owner Commands

CommandDescription
owner serversDisplay all servers in database
owner prefix <new prefix>Change bot prefix for commands
owner botdescription <new description>Update bot description

GW2 Commands

CommandDescription
gw2 accountDisplay your GW2 account information
gw2 charactersDisplay your GW2 characters information
gw2 sessionDisplay your last game session data
gw2 worlds naList all NA worlds with WvW tier
gw2 worlds euList all EU worlds with WvW tier
gw2 wiki <search>Search the Guild Wars 2 wiki
gw2 info <search>Information about a given name/skill/rune

GW2 Config Commands

CommandDescription
gw2 config listList all GW2 configurations
gw2 config session [on, off]Toggle recording of user sessions

GW2 Key Commands

CommandDescription
gw2 key add [api_key]Add your first GW2 API key
gw2 key update [api_key]Update your existing API key
gw2 key removeRemove your GW2 API key
gw2 key infoShow your API key information

GW2 WvW Commands

CommandDescription
gw2 wvw info [world]Info about a WvW world
gw2 wvw match [world]WvW match scores
gw2 wvw kdr [world]WvW kill/death ratios

Development and Testing

Requires UV to be installed.

Setup

uv lock --upgrade && uv sync --all-extras --all-groups

Running Tests

# Unit tests
poe test# Integration tests (requires Docker for testcontainers)
poe test-integration
# All tests (unit + integration + hadolint + docker)
poe tests

Other Tasks

# Run linter (ruff)
poe linter
# Update all dev dependencies
poe updatedev
# Run database migrations
poe migration
# Profile unit tests
poe profile
# Profile integration tests
poe profile-integration

Credits

License

Released under the MIT License

Support

If you find this project helpful, consider supporting development.

Sponsor on GitHubBuy Me a Coffee at ko-fi.comDonate via PayPal

Releases

Sponsor this project

Used by

Contributors

Languages