An advanced, asynchronous Python-based Discord bot designed for developer utilities, dynamic interaction handling, AutoSharded scalability, and specialized integrations such as the Library of Babel index and automated codebase sanitization.
- ** High Performance & Scalability**: Built with
discord.ext.commands.AutoShardedBotfor handling 2,500+ servers smoothly. - ** Library of Babel Integration**: Deep search and precise hex coordinate lookups via hybrid commands (
!babel,/babel) and inline message listeners (k:keyword,f:hex:wall:shelf:vol:page). - ** Built-in Code Sanitizer**: Dedicated script for recursively stripping Python comments (
#) and Unicode/Discord emojis across the codebase while preserving strings. - ** Advanced Security & Checks**: Global command blacklist filters, owner-restricted operations, and secure DM handling.
- ** Interaction Deferrals & Webhooks**: Prevents standard 3-second Discord timeouts on high-latency operations with
interaction.response.defer(). - ** Auto-Publishing**: Automatically crossposts news and announcement channel updates to follower guilds.
- ** Dynamic Rich Presence**: Real-time status update commands for activity monitoring.
| Component | Technology | Purpose |
|---|---|---|
| Language | Python 3.10+ | Core language runtime |
| Framework | discord.py v2.x |
Discord API interaction & slash commands |
| HTTP Client | aiohttp |
Non-blocking asynchronous network requests |
| HTML Parser | BeautifulSoup4 |
Web scraping search results from external services |
| Tokenization | tokenize (Standard Lib) |
Safe AST/Token-based comment removal |
coder-bot/
├── cogs/
│ └── babel.py # Library of Babel search and lookup cog
├── clean.py # Standalone Python comment & emoji stripper
├── main.py # Main bot entry point and initialization
├── requirements.txt # Dependencies
└── README.md # Project documentation
- Python 3.10 or higher
- A Discord Developer Account & Bot Token (Discord Developer Portal)
git clone https://github.com/your-username/coder-bot.git
cd coder-bot
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
Required Packages:
discord.py>=2.3.0 aiohttp>=3.8.0 beautifulsoup4>=4.12.0
Create a .env or standard configuration file in the project root:
DISCORD_TOKEN=your_bot_token_here
COMMAND_PREFIX=!
OWNER_ID=your_discord_user_id
Make sure the following Privileged Gateway Intents are enabled in the Discord Developer Portal under your Application settings:
MESSAGE_CONTENTGUILD_MESSAGES
| Command / Event | Description | Access |
|---|---|---|
!set_presence <game> |
Updates the bot's status and rich presence activity. | Owner |
!bot_info |
Displays developer application metadata and flag statuses. | Owner |
!temp_alert |
Sends an alert message that automatically deletes after 5 seconds. | Everyone |
!send_dm <user> <text> |
Delivers a direct message to a user with exception safety. | Everyone |
on_message |
Automatic cross-publishing for News channels. | Automatic |
The Babel cog connects your Discord server directly to libraryofbabel.info.
- Search by Keyword:
!babel search universal library
/babel search query:universal library
- Fetch Exact Coordinates:
!babel fetch hex_id:410 wall:1 shelf:2 volume:3 page:12
You can trigger the Babel search or coordinate fetch inline within any channel message without using explicit command prefixes:
- Keyword Trigger: Type
k:<keyword>anywhere in your message.
Hey check this out k:truth and wisdom
- Coordinate Trigger: Type
f:<hex_id>:<wall>:<shelf>:<volume>:<page>anywhere in your message.
Look at page f:0:1:2:3:15
The project includes clean.py, a script designed to clean Python code by removing all # comments (while preserving # inside strings) and stripping Unicode & custom Discord emojis.
To clean all .py files inside ~/coder-bot/:
python3 ~/clean.py
- Uses Python's native
tokenizemodule to distinguish between code comments and string literals containing#. - Uses regular expressions to strip Unicode emojis and Discord custom emojis (
<:name:id>). - Automatically cleans empty lines left behind by deleted comment blocks.
For bots deployed across thousands of servers, AutoSharding is enabled natively in main.py:
import discord
from discord.ext import commands
intents = discord.Intents.default()
intents.message_content = True
bot = commands.AutoShardedBot(
command_prefix="!",
intents=intents
)Create a systemd service file at /etc/systemd/system/coderbot.service:
[Unit]
Description=Coder Discord Bot
After=network.target
[Service]
Type=simple
User=server
WorkingDirectory=/home/server/coder-bot
ExecStart=/home/server/coder-bot/venv/bin/python main.py
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
Enable and start the service:
sudo systemctl daemon-reload
sudo systemctl enable coderbot
sudo systemctl start coderbot
- Fork the repository.
- Create a feature branch (
git checkout -b feature/NewFeature). - Run
python3 ~/clean.pyprior to committing to ensure uniform formatting. - Commit your changes (
git commit -m 'Add NewFeature'). - Push to the branch (
git push origin feature/NewFeature). - Open a Pull Request.
Distributed under the MIT License. See LICENSE for more information.