A Discord bot that translates messages using Ollama when users react with flag emojis. This bot provides real-time, AI-powered translation for multiple languages, making communication seamless in multilingual servers.
- 🌍 Real-time translations triggered by flag emojis
- 🔤 Supports multiple languages:
- French (🇫🇷), Spanish (🇪🇸), German (🇩🇪), Italian (🇮🇹)
- Japanese (🇯🇵), Korean (🇰🇷), Chinese (🇨🇳), Portuguese (🇵🇹)
- Russian (🇷🇺), Greek (🇬🇷), English (🇦🇺 🇳🇿 🇬🇧 🇺🇸 🇨🇦 🇮🇪 🇯🇲 🇧🇿 🇹🇹 🇧🇧 🇧🇸 🇫🇯 🇸🇨 🇸🇬 🇲🇹)
- 🤖 Easy-to-setup bot with local AI translation using Ollama
- Python 3.11.4
- Ollama installed on your machine (Get Ollama)
- Discord oAuth Bot Token (Create a bot)
- Required Python libraries:
discord.py
andrequests
First, install Ollama and the Llama2 model, which powers the bot's translations.
# Install Ollama and pull Llama2 model
ollama pull llama2
# Start Ollama with the Llama2 model
ollama run llama2
-
Clone this repository:
git clone https://github.com/psenger/discord-translator-bot.git cd discord-translator-bot
-
Create a virtual environment and activate it:
python -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt pip install -e .
-
Create a
.env
file in the project root with your bot token:DISCORD_TOKEN=your_bot_token_here OLLAMA_MODEL=llama3.1:8b OLLAMA_URL=http://localhost:11434/api/generate
-
Run the bot:
python src/discord_translator/bot.py
- Send a message in a channel where the bot has access.
- React to the message with a flag emoji representing the desired language.
- The bot will reply with the translated text.
To ensure everything works correctly:
# Create and activate virtual environment
python3.11 -m venv .venv
source .venv/bin/activate # On Windows: venv\Scripts\activate
# First install requirements
pip install -r requirements.txt
# Then install your package in editable mode
pip install -e .
# Run tests with coverage report
pytest --cov=src/discord_translator tests/ --cov-report term-missing --cov-report html
Remove temporary files and environments:
# Remove virtual environment
rm -rf .venv
# Remove cached Python files
find . -type f -name "*.pyc" -delete
find . -type d -name "__pycache__" -delete
# Remove coverage reports
rm -rf htmlcov
rm .coverage
Check your setup:
python --version
pip --version
pip list
xcode-select --version
brew --version
source .venv/bin/activate
python src/discord_translator/bot.py
- Log in to the Discord Developer Portal.
- Create a new application and add a bot:
- Go to the Bot section.
- Enable:
- Message Content Intent
- Server Members Intent
- Copy the bot token (you'll use this in your
.env
file). - Use the OAuth2 URL generator to create an invite link:
- Scope:
bot
- Bot Permissions:
View Channels
,Send Messages
,Read Message History
,Add Reactions
- Integration Type:
guild install
- Scope:
- Use the generated link to invite your bot to your server.
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.