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.
pip install discord-webhookVerified import paths — ran on the pinned version, not inferred.
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.
Ensure `url` is a single string. For `.edit()` and `.delete()`, call them without arguments after the webhook has been executed and its ID populated.
Update calls from `del_embed_field()` to `delete_embed_field()`.
Remove the `remove_files` parameter from `.execute()` calls. The library now handles file clearing automatically.
Update any exception handling or imports of `ColourNotInRangeException` to `ColorNotInRangeException`.
Upgrade to version 1.2.1 or newer. If stuck on an older version, explicitly set `tts=False` when using `timeout` if TTS is not desired.
For full flexibility, ensure you are on version 1.4.0 or newer if passing strings. Otherwise, provide `datetime` objects for versions >=1.2.0, or rely on automatic timestamp generation if no argument is passed.
Install the package using pip: `pip install discord-webhook`
Verify that the webhook URL is correctly copied from Discord, is still active, and has not been deleted. Create a new webhook if necessary and update your code with the new URL.
Ensure that your `DiscordWebhook` object or its `execute()` method includes valid `content`, `embeds`, or `files` parameters. For example, `webhook = DiscordWebhook(url='YOUR_WEBHOOK_URL', content='Your message here')`.
Check the webhook's permissions in Discord (ensure it can send messages in the channel). If rate-limited, the library's `rate_limit_retry=True` (default) should handle it, but excessive requests might still lead to this. Verify the webhook URL again for any errors.
Add the `DiscordEmbed` object to the `DiscordWebhook` object using `add_embed()` and then call `execute()` on the `DiscordWebhook` object.