dhooks-lite

1.1.0 · active · verified Fri Apr 17

dhooks-lite is a lightweight Python wrapper for interacting with Discord webhooks, focusing on essential functionality for sending messages and embeds. It provides a simpler alternative to the original `dhooks` library. The current version is 1.1.0, and it has a moderate release cadence, with the last update in mid-2023.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a `Webhook` object and send both a simple text message and a more complex message containing a Discord-API-compliant embed dictionary.

import os
from dhooks_lite import Webhook

# It's recommended to use an environment variable for security.
# Replace with your actual webhook URL or set DISCORD_WEBHOOK_URL in your environment.
webhook_url = os.environ.get(
    "DISCORD_WEBHOOK_URL",
    "https://discord.com/api/webhooks/YOUR_ID/YOUR_TOKEN" # Placeholder, replace with your actual URL
)

if "YOUR_ID" in webhook_url:
    print("Warning: Please replace the placeholder webhook URL or set DISCORD_WEBHOOK_URL environment variable.")
    # For demonstration, we'll proceed, but real use requires a valid URL.

try:
    webhook = Webhook(webhook_url)

    # 1. Send a simple text message
    webhook.send("Hello from `dhooks-lite`! This is a simple message.")
    print("Sent simple message.")

    # 2. Send a message with an embed (embeds must be dicts conforming to Discord API)
    embed_data = {
        "title": "dhooks-lite Embed Example",
        "description": "This embed demonstrates sending structured data.",
        "color": 0x3498DB, # Hex color code (e.g., Discord's blurple)
        "fields": [
            {"name": "Feature 1", "value": "Lightweight", "inline": True},
            {"name": "Feature 2", "value": "Easy to Use", "inline": True}
        ],
        "footer": {"text": "Powered by dhooks-lite"},
        "timestamp": "2023-10-27T10:00:00.000Z" # ISO 8601 timestamp
    }
    webhook.send(embeds=[embed_data])
    print("Sent message with embed.")

except Exception as e:
    print(f"An error occurred: {e}")
    print("Please ensure your Discord webhook URL is valid and active.")

view raw JSON →