Skip to content

Configuration Guide

Iván Pérez edited this page Jun 10, 2025 · 2 revisions

Ui-Py Configuration Guide

This guide explains how to configure Ui-Py for different environments and use cases.

Environment Variables

Ui-Py uses environment variables for configuration. The following variables are available:

Variable Required Description
TOKEN Required Your Discord bot token
STEAM_TOKEN Optional Steam API token

Setting Environment Variables

In a Development Environment

# Linux/macOS
export TOKEN="your_token_here"

# Windows (Command Prompt)
set TOKEN=your_token_here

# Windows (PowerShell)
$env:TOKEN = "your_token_here"

In Docker

When using Docker, set environment variables in the docker-compose.yml file:

services:
  discord:
    build: ./
    restart: always
    container_name: ui
    environment:
      - TOKEN=${TOKEN}

Then, either:

  • Define the variable in your shell before running docker-compose
  • Create a .env file in the same directory as your docker-compose.yml

Example .env file:

TOKEN=your_token_here

In a Production Environment

For production deployments, consider using a proper secrets management system:

  • Kubernetes Secrets
  • Docker Swarm Secrets
  • HashiCorp Vault
  • Cloud provider secret management (AWS Secrets Manager, Google Secret Manager, etc.)

Advanced Configuration

Extending the Bot Configuration

If you need to add more configuration options, you can extend the UiPy class in main.py:

  1. Add new environment variables to retrieve configuration values
  2. Add corresponding attributes to the UiPy class
  3. Update your cogs to use these new configuration values

Example of adding a custom prefix:

# In main.py
PREFIX = environ.get("PREFIX", "!")  # Default to "!" if not set

class UiPy(commands.AutoShardedBot):
    def __init__(self):
        intents = Intents.default()
        intents.message_content = True
        super().__init__(
            description="Do you want coffee, or tea?",
            command_prefix=PREFIX,  # Use the PREFIX from environment
            case_insensitive=True,
            intents=intents,
        )
        self._bot_token = TOKEN
        self.session: ClientSession | None = None
        self.color = 0xFF3351
        self.prefix = PREFIX  # Store for use in cogs

Configuration Best Practices

  1. Never commit tokens or secrets to your Git repository
  2. Use environment variables for configuration that varies between environments
  3. Provide sensible defaults for optional configuration
  4. Validate configuration at startup to fail fast if required values are missing
  5. Document all configuration options in your README or wiki
  6. Consider using a configuration library for more complex scenarios

Discord Application Configuration

Besides environment variables, you'll need to configure your Discord application in the Discord Developer Portal:

Bot Permissions

When adding your bot to a server, ensure it has these permissions:

  • Read Messages/View Channels: Required to see commands in channels
  • Send Messages: Required to respond to commands
  • Embed Links: For rich embed responses
  • Manage Messages: Required for the /clear command
  • Add Reactions: If your bot uses reactions
  • Use Slash Commands: Required for all slash commands

Privileged Intents

Ui-Py requires the following privileged intents:

  • Message Content: Required for the link redirection feature

To enable this intent:

  1. Go to the Discord Developer Portal
  2. Select your application
  3. Navigate to the "Bot" tab
  4. Scroll down to "Privileged Gateway Intents"
  5. Enable "Message Content Intent"
  6. Save changes

OAuth2 URL Generator

To generate an invite link for your bot:

  1. Go to the Discord Developer Portal
  2. Select your application
  3. Navigate to "OAuth2" > "URL Generator"
  4. Select the "bot" and "applications.commands" scopes
  5. Select the permissions your bot needs
  6. Copy and use the generated URL to invite your bot to servers

Troubleshooting

If your bot doesn't respond or behaves unexpectedly:

  • Check that the TOKEN environment variable is set correctly
  • Verify that the Message Content Intent is enabled in the Discord Developer Portal
  • Ensure that the bot has the necessary permissions in the Discord server
  • Check logs for any error messages
  • Use the /info command to verify that the bot is running correctly

Clone this wiki locally