-
Notifications
You must be signed in to change notification settings - Fork 0
Configuration Guide
This guide explains how to configure Ui-Py for different environments and use cases.
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 |
# Linux/macOS
export TOKEN="your_token_here"
# Windows (Command Prompt)
set TOKEN=your_token_here
# Windows (PowerShell)
$env:TOKEN = "your_token_here"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
.envfile in the same directory as yourdocker-compose.yml
Example .env file:
TOKEN=your_token_here
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.)
If you need to add more configuration options, you can extend the UiPy class in main.py:
- Add new environment variables to retrieve configuration values
- Add corresponding attributes to the
UiPyclass - 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- Never commit tokens or secrets to your Git repository
- Use environment variables for configuration that varies between environments
- Provide sensible defaults for optional configuration
- Validate configuration at startup to fail fast if required values are missing
- Document all configuration options in your README or wiki
- Consider using a configuration library for more complex scenarios
Besides environment variables, you'll need to configure your Discord application in the Discord Developer Portal:
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
/clearcommand - Add Reactions: If your bot uses reactions
- Use Slash Commands: Required for all slash commands
Ui-Py requires the following privileged intents:
- Message Content: Required for the link redirection feature
To enable this intent:
- Go to the Discord Developer Portal
- Select your application
- Navigate to the "Bot" tab
- Scroll down to "Privileged Gateway Intents"
- Enable "Message Content Intent"
- Save changes
To generate an invite link for your bot:
- Go to the Discord Developer Portal
- Select your application
- Navigate to "OAuth2" > "URL Generator"
- Select the "bot" and "applications.commands" scopes
- Select the permissions your bot needs
- Copy and use the generated URL to invite your bot to servers
If your bot doesn't respond or behaves unexpectedly:
- Check that the
TOKENenvironment 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
/infocommand to verify that the bot is running correctly