How to Build a Discord Translation Bot with Simple Command
Learn how to build a lightweight Discord translation bot using Python and Google Translate API—no prior bot dev experience needed! 🌐✨
October 18, 2026 · 1077 views
Building a Discord translation bot is one of the most practical and beginner-friendly bot projects you can undertake—especially if your server spans multiple languages or hosts international communities. Whether you're managing a global gaming clan, an open-source contributor hub, or a language-learning study group, a translation bot adds real value with minimal overhead. In this step-by-step Discord bot tutorial, we’ll walk you through building a fully functional translation bot that responds to a simple command like /translate en→es Hello world! — all in under 100 lines of clean Python code.
No need for complex infrastructure or deep backend knowledge: we’ll use discord.py (v2.3+), the free googletrans==4.0.0-rc1 library (a maintained fork), and environment-based API safety. By the end, you’ll have a production-ready, low-latency translation bot ready to deploy on a $5/month VPS or even a free-tier Replit instance 🚀
Why Use a Custom Translation Bot Instead of Third-Party Bots?
While bots like MEE6 or Dyno offer translation features, they’re often buried in premium tiers, lack customization, or don’t support real-time inline translation. A custom Discord translation bot gives you:
- ✅ Full control over supported languages and fallback behavior
- ✅ Zero dependency on external bot dashboards or subscription plans
- ✅ Ability to log usage (for moderation insights) or add auto-translate reactions
- ✅ Seamless integration with your existing moderation or welcome flows
Plus—unlike many outdated tutorials—you won’t need deprecated APIs (RIP Google Translate v2) or messy API keys. The modern googletrans client works without authentication, making it ideal for small-to-mid-sized servers.
Prerequisites & Setup Overview
Before writing any code, gather these essentials:
- A Discord Developer Account (discord.com/developers)
- Python 3.9+ installed locally or in your cloud IDE
- Basic familiarity with terminal/command line and
pip - Optional but recommended: A
.envfile manager (we’ll usepython-dotenv)
💡 Pro Tip: If you're new to Discord bot development, check out DiscordCraft — their free starter templates include pre-configured requirements.txt, logging scaffolds, and slash-command boilerplates that cut setup time by ~70%.
Step 1: Create Your Discord Application & Bot User
Follow these steps precisely to avoid common permission pitfalls:
- Go to the Discord Developer Portal
- Click "New Application", give it a name (e.g.,
LangBridge), and hit Create - Navigate to the Bot tab → Add Bot → Confirm
- Copy the Token (⚠️ never share this publicly!) and save it securely
- Under OAuth2 → URL Generator, select:
- Scopes:
botandapplications.commands - Permissions:
Send Messages,Embed Links,Use Slash Commands(minimum)
- Scopes:
- Paste the generated URL into your browser and invite the bot to your test server
[Image: Discord OAuth2 URL generator with scopes and permissions selected]
Step 2: Install Dependencies & Scaffold Project
Create a new folder (e.g., discord-translator) and initialize a virtual environment:
python -m venv .venv
source .venv/bin/activate # macOS/Linux
# Or on Windows: .venv\Scripts\activate
Now install required packages:
pip install discord.py==2.3.2 googletrans==4.0.0-rc1 python-dotenv
⚠️ Important: Use
googletrans==4.0.0-rc1, not the unmaintainedgoogletrans==3.x. Version 4 fixes SSL errors, adds async support, and respects rate limits.
Create two files:
main.py— your bot’s entry point.env— for secure token storage
In .env, add:
DISCORD_TOKEN=your_bot_token_here
Step 3: Write the Core Translation Logic
Open main.py. We’ll build a slash command /translate that accepts:
target: target language code (e.g.,fr,ja,pt)text: the string to translate- Optional
source: source language (auto-detected if omitted)
Here’s the full, production-safe implementation:
import os
import discord
from discord import app_commands
from googletrans import Translator
from dotenv import load_dotenv
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
intents = discord.Intents.default()
intents.message_content = True
client = discord.Client(intents=intents)
tree = app_commands.CommandTree(client)
translator = Translator()
@tree.command(name='translate', description='Translate text between languages')
@app_commands.describe(
target='Target language code (e.g., "es", "de", "zh-cn")',
text='Text to translate',
source='Source language code (optional; auto-detected if blank)'
)
async def translate(interaction: discord.Interaction, target: str, text: str, source: str = None):
await interaction.response.defer(ephemeral=False)
try:
result = translator.translate(text, src=source or 'auto', dest=target)
# Format response with detected source + flag emojis (if available)
src_lang = result.src.upper() if result.src != 'auto' else 'AUTO'
dest_lang = result.dest.upper()
embed = discord.Embed(
title=f'🌍 Translated from {src_lang} → {dest_lang}',
description=f'**Original:** `{text}`\n**Translation:** `{result.text}`',
color=0x4CAF50
)
embed.set_footer(text=f'Translated via Google Translate • LangBridge v1.0')
await interaction.followup.send(embed=embed)
except Exception as e:
await interaction.followup.send(
f'❌ Translation failed: {str(e)}. Please check language codes.',
ephemeral=True
)
@client.event
async def on_ready():
print(f'✅ {client.user} is online and syncing commands...')
await tree.sync() # Syncs slash commands globally (use guild=... for testing)
client.run(TOKEN)
📌 Note: This uses Discord’s native slash command framework (app_commands) — no more prefix-based parsing or regex headaches!
Step 4: Run, Test & Troubleshoot
Start your bot:
python main.py
Once online, type /translate in your server — you’ll see the auto-generated UI. Try:
/translate target:fr text:Hello world!→ Bonjour le monde !/translate target:ja source:en text:See you tomorrow!→ また明日!
🔧 Common issues & fixes:
- ❌ “Command not found”: Wait up to 1 hour for global sync, or force-sync to a test guild using
tree.sync(guild=discord.Object(id=YOUR_GUILD_ID)) - ❌ “SSL certificate verify failed”: Upgrade
certifi:pip install --upgrade certifi - ❌ Empty response or timeout: Add
timeout=10totranslator.translate(..., timeout=10)
Step 5: Enhance With Pro Features (Optional)
Once the core works, level up your Discord translation bot with these lightweight upgrades:
Auto-Detect & React Translation
Add this inside on_message() to react with 🌐 when detecting non-native messages (requires intents.message_content = True and proper permissions):
@client.event
async def on_message(message):
if message.author == client.user:
return
# Detect likely non-English message (simplified heuristic)
if len(message.content) > 5 and not message.content.isascii():
await message.add_reaction('🌐')
# Later: attach a context menu or button to translate on click
Language Code Helper Command
Add /languages to list common ISO-639-1 codes:
@tree.command(name='languages', description='List common language codes')
async def languages(interaction: discord.Interaction):
langs = {'English': 'en', 'Spanish': 'es', 'French': 'fr', 'Japanese': 'ja', 'Chinese': 'zh-cn', 'Korean': 'ko', 'Arabic': 'ar'}
desc = '\n'.join([f'`{code}` — {name}' for name, code in langs.items()])
await interaction.response.send_message(f'✅ Supported language codes:\n{desc}', ephemeral=True)
Quick Tips for Long-Term Success
- 🧩 Keep it simple first: Launch with
/translateonly — add batch translation or history later - 📦 Containerize early: Wrap your bot in Docker for easy deployment across environments
- 🛑 Respect rate limits: Google Translate doesn’t enforce strict quotas for light usage, but add
asyncio.sleep(0.3)between rapid calls in high-traffic servers - 📊 Log translations (anonymously): Store timestamps + language pairs (not raw text) to spot popular language needs
- 🌐 Support regional variants: Accept
zh-tw,pt-br,en-gb—googletranshandles them natively
FAQ: Your Top Translation Bot Questions — Answered
Q: Does this require a paid Google Cloud API key?
A: No — googletrans==4.0.0-rc1 scrapes Google’s public translate website (like a browser), so it’s free and keyless. ✅
Q: Can I translate entire messages or attachments?
A: Not out-of-the-box — this tutorial focuses on text. For PDF/image OCR + translation, layer in pytesseract + pdf2image, but expect latency and complexity spikes.
Q: Is this safe for large servers?
A: Yes — it’s stateless, single-threaded, and makes <1 request per command. Just monitor memory if running alongside 10+ other bots on same host.
Q: How do I update language support?
A: googletrans supports 108+ languages. No code changes needed — just use valid ISO codes.
Final Thoughts: Your Bot Is Ready — Now Scale the Impact 💫
You’ve just built a fully functional, maintainable Discord translation bot — no black-box dependencies, no vendor lock-in, and zero monthly fees. That /translate command may seem small, but it’s the foundation for inclusive communication, smoother onboarding, and stronger cross-cultural engagement.
Next, consider extending it with:
- A
/translate-set-defaultcommand to assign per-channel preferred languages - Integration with your ticketing system to auto-translate user-submitted help requests
- A web dashboard (Flask/FastAPI) showing real-time translation stats
And remember: great Discord server tools aren’t about complexity — they’re about solving one real problem, exceptionally well. 🎯
For more battle-tested snippets, command patterns, and CI/CD-ready bot templates, explore the open-source collection at DiscordCraft — where community-driven tooling meets production rigor.
Happy coding — and happy translating! 🌐✨