Cordhook is a clean, lightweight Python wrapper around the Discord Webhook API.
It provides a developer-friendly way to send rich messages, embeds, and file attachments with built-in validation, retry logic, and error handling.
- Simple interface for sending messages and embeds
- Full support for Discord embed customization
- File attachment support
- Auto retry logic with exponential backoff
- Custom exception handling for common issues
- Utility functions for formatting, truncating, and validating payloads
pip install cordhookfrom cordhook import Webhook
wh = Webhook("https://discord.com/api/webhooks/...")
wh.set_content("Hello, world!")\\
.add_embed("Embed Title", "This is a test")\\
.send()You can use the create_embed() helper for more control:
from cordhook import create_embed
embed = create_embed(
title="Sample Embed",
description="Generated with Cordhook",
footer_text="Sent via Python",
timestamp=True
)- retry_request(func, retries=3) – retries any function with optional backoff
- validate_url(url) – checks if a webhook URL is valid
- json_pretty_print(obj) – nicely formats any JSON or dict
- truncate_text(text, limit=1024) – prevents hitting Discord text limits
Cordhook raises specific exceptions so you can catch and handle errors cleanly:
- WebhookException
- InvalidPayloadException
- RateLimitException
- FileAttachmentException
Webhook("url")
.set_content("With a file!")
.attach_file("cat.png")
.send()MIT License — free to use, modify, and distribute
Open an issue or PR to suggest improvements or fix bugs.