Discord Webhook

1.4.1 · active · verified Sun Apr 12

discord-webhook is a Python library designed to easily send Discord webhooks. It simplifies the process of sending messages, embeds, files, and managing webhook interactions with Discord's API. The current version is 1.4.1, and it maintains an active development cycle with frequent updates addressing features, fixes, and occasionally breaking changes.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to send a Discord webhook with an embedded message. It retrieves the webhook URL from an environment variable, constructs a `DiscordEmbed` with a title, description, color, fields, footer, and timestamp, then adds it to a `DiscordWebhook` instance and executes it. Remember to set the `DISCORD_WEBHOOK_URL` environment variable.

import os
from discord_webhook import DiscordWebhook, DiscordEmbed

webhook_url = os.environ.get('DISCORD_WEBHOOK_URL', '')

if webhook_url:
    webhook = DiscordWebhook(url=webhook_url)

    # Create an embed
    embed = DiscordEmbed(
        title='New Event Alert',
        description='A new event has been scheduled. Check it out!',
        color='03b2f8' # Hex color without the #
    )

    # Add fields to the embed
    embed.add_embed_field(name='Event Name', value='Python Dev Meetup')
    embed.add_embed_field(name='Date', value='2025-08-01', inline=True)
    embed.add_embed_field(name='Time', value='19:00 UTC', inline=True)

    # Set footer and timestamp
    embed.set_footer(text='Powered by discord-webhook')
    embed.set_timestamp()

    # Add the embed to the webhook
    webhook.add_embed(embed)

    # Execute the webhook
    try:
        response = webhook.execute()
        print(f"Webhook sent successfully. Status: {response.status_code}")
    except Exception as e:
        print(f"Failed to send webhook: {e}")
else:
    print("DISCORD_WEBHOOK_URL environment variable not set. Skipping webhook send.")

view raw JSON →