A lightweight Discord bot built with Python and discord.py. It supports:
- Translation via
googletrans - Wikipedia summaries
- A simple chatbot powered by
chatbotTemplate.template - Clean embeds for longer replies
Command prefix: ~ (the bot only processes messages that start with ~).
- Python: 3.10+
- Libraries:
discord.py,googletrans==4.0.0-rc1,wikipedia,requests,python-dotenv(recommended) - Patterns: commands extension, async event loop, simple embed pagination
DiscordBot/
├─ translatorBot.py # entrypoint
├─ chatbotTemplate/
│ └─ chatbotTemplate.template # template consumed by the chatbot
├─ LICENSE
└─ README.md
- Go to the Discord Developer Portal → Applications → New Application
- Add a Bot, copy its token, and enable Message Content Intent
- OAuth2 → URL Generator → select
botscope + permissions → invite the bot to your server
python -m venv .venv
# Windows
. .venv\Scripts\activate
# macOS/Linux
# source .venv/bin/activate
pip install discord.py googletrans==4.0.0-rc1 wikipedia requests python-dotenvOption A (quick): in translatorBot.py, replace
bot.run('insertTokenHere')with your real token string.
Option B (recommended): use a .env file:
- Create
.env:DISCORD_TOKEN=your-bot-token-here - At the top of
translatorBot.py:import os from dotenv import load_dotenv load_dotenv() TOKEN = os.getenv("DISCORD_TOKEN") # ... bot.run(TOKEN)
Never commit
.envto git; add it to.gitignore.
python translatorBot.pyIf it starts correctly, the console will print the logged-in user.
~translate en hola mundo
~translate es "good morning, travelers"
~wiki event loop
~wiki texas barbecue
~chat what is polymorphism?
All commands must start with
~due to the prefix gate inon_message.
- Embeds: long wiki summaries are split into multiple embeds (2,048 char limit per embed).
- Chatbot:
@register_call("whoIs")bridges to Wikipedia summaries when the template calls it. - Intents: make sure Message Content Intent is enabled both in the portal and in code if you set custom
Intents.
- Convert text commands to slash commands (
app_commands) - Add per-guild config (prefix/language) and better error messages
- Add retries/backoff + structured logging for external API calls
- Unit tests for wiki/translate helpers
See LICENSE.