{"id":13592927,"url":"https://github.com/lovvskillz/python-discord-webhook","last_synced_at":"2025-05-15T10:02:39.446Z","repository":{"id":37951382,"uuid":"145297532","full_name":"lovvskillz/python-discord-webhook","owner":"lovvskillz","description":"execute discord webhooks","archived":false,"fork":false,"pushed_at":"2025-03-05T11:54:37.000Z","size":621,"stargazers_count":510,"open_issues_count":23,"forks_count":80,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-14T16:53:35.241Z","etag":null,"topics":["discord","discord-webhooks","embeds","execute-discord-webhooks","python","python-discord-webhook","webhook"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lovvskillz.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-08-19T11:33:54.000Z","updated_at":"2025-04-10T04:56:09.000Z","dependencies_parsed_at":"2024-06-09T04:42:44.644Z","dependency_job_id":"d6ebd258-82c3-4cc9-849a-a2a7ec8e4969","html_url":"https://github.com/lovvskillz/python-discord-webhook","commit_stats":{"total_commits":161,"total_committers":20,"mean_commits":8.05,"dds":"0.44099378881987583","last_synced_commit":"64e5fd52c8d171442762a793c224d983a4202251"},"previous_names":[],"tags_count":30,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lovvskillz%2Fpython-discord-webhook","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lovvskillz%2Fpython-discord-webhook/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lovvskillz%2Fpython-discord-webhook/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lovvskillz%2Fpython-discord-webhook/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lovvskillz","download_url":"https://codeload.github.com/lovvskillz/python-discord-webhook/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254319716,"owners_count":22051072,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["discord","discord-webhooks","embeds","execute-discord-webhooks","python","python-discord-webhook","webhook"],"created_at":"2024-08-01T16:01:14.786Z","updated_at":"2025-05-15T10:02:38.561Z","avatar_url":"https://github.com/lovvskillz.png","language":"Python","readme":"# Python Discord webhook\n\n[![GitHub license](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://raw.githubusercontent.com/lovvskillz/python-discord-webhook/master/LICENSE)\n[![PyPI version](https://badge.fury.io/py/discord-webhook.svg)](https://badge.fury.io/py/discord-webhook)\n[![Downloads](https://pepy.tech/badge/discord-webhook)](https://pepy.tech/project/discord-webhook)\n\nEasily send Discord webhooks with Python (also has [async support](#async-support))\n\n## Install\n\nInstall via pip:\n```\npip install discord-webhook\n```\n\n## Examples\n\n* [Basic Webhook](#basic-webhook)\n* [Create Multiple Instances / Use multiple URLs](#create-multiple-instances)\n* [Get Webhook by ID](#get-webhook-by-id)\n* [Send Webhook to a thread](#send-webhook-to-a-thread)\n* [Manage Being Rate Limited](#manage-being-rate-limited)\n* [Embedded Content](#webhook-with-embedded-content)\n* [Edit Webhook Message](#edit-webhook-messages)\n* [Delete Webhook Message](#delete-webhook-messages)\n* [Send Files](#send-files)\n* [Remove Embeds and Files](#remove-embeds-and-files)\n* [Allowed Mentions](#allowed-mentions)\n* [Use Message Flags](#use-message-flags)\n* [Use Proxies](#use-proxies)\n* [Timeout](#timeout)\n* [Async Support](#async-support)\n\n### Basic Webhook\n\n```python\nfrom discord_webhook import DiscordWebhook\n\nwebhook = DiscordWebhook(url=\"your webhook url\", content=\"Webhook Message\")\nresponse = webhook.execute()\n```\n\n### Create multiple instances\nIf you want to use multiple URLs you need to create multiple instances.\n\n```python\nfrom discord_webhook import DiscordWebhook\n\n# you can provide any kwargs except url\nwebhook1, webhook2 = DiscordWebhook.create_batch(urls=[\"first url\", \"second url\"], content=\"Webhook Message\")\nresponse1 = webhook1.execute()\nresponse2 = webhook2.execute()\n```\n![Image](img/multiple_urls.png \"Multiple Urls Result\")\n\n### Get Webhook by ID\nYou can access a webhook that has already been sent by providing the ID.\n\n````python\nfrom discord_webhook import DiscordWebhook\n\nwebhook = DiscordWebhook(url=\"your webhook url\", id=\"your webhook message id\")\n# now you could delete or edit the webhook\n# ...\n````\n### Send Webhook to a thread\nYou can send a message to an existing thread by setting `thread_id` or create a new thread in a forum channel by using a `thread_name`.\n```python\nfrom discord_webhook import DiscordWebhook\n\n# send to an existing thread\nwebhook = DiscordWebhook(url=\"your webhook url\", thread_id=\"the thread id\")\nwebhook.execute()\n\n# create a new thread in a forum channel\nwebhook = DiscordWebhook(url=\"your webhook url\", thread_name=\"some-thread-name\")\nwebhook.execute()\n```\n\n### Manage being Rate Limited\n\n```python\nfrom discord_webhook import DiscordWebhook\n\n# if rate_limit_retry is True then in the event that you are being rate \n# limited by Discord your webhook will automatically be sent once the \n# rate limit has been lifted\nwebhook = DiscordWebhook(url=\"your webhook url\", rate_limit_retry=True, content=\"Webhook Message\")\nresponse = webhook.execute()\n```\n\n![Image](img/basic_webhook.png \"Basic Example Result\")\n\n### Webhook with Embedded Content\n\n```python\nfrom discord_webhook import DiscordWebhook, DiscordEmbed\n\nwebhook = DiscordWebhook(url=\"your webhook url\")\n\n# create embed object for webhook\n# you can set the color as a decimal (color=242424) or hex (color=\"03b2f8\") number\nembed = DiscordEmbed(title=\"Your Title\", description=\"Lorem ipsum dolor sit\", color=\"03b2f8\")\n\n# add embed object to webhook\nwebhook.add_embed(embed)\n\nresponse = webhook.execute()\n```\n\n![Image](img/simple_embed.png \"Basic Embed Example Result\")\n\n```python\nfrom discord_webhook import DiscordWebhook, DiscordEmbed\n\nwebhook = DiscordWebhook(url=\"your webhook url\")\n\n# create embed object for webhook\nembed = DiscordEmbed(title=\"Your Title\", description=\"Lorem ipsum dolor sit\", color=\"03b2f8\")\n\n# set author\nembed.set_author(name=\"Author Name\", url=\"author url\", icon_url=\"author icon url\")\n\n# set image\nembed.set_image(url=\"your image url\")\n\n# set thumbnail\nembed.set_thumbnail(url=\"your thumbnail url\")\n\n# set footer\nembed.set_footer(text=\"Embed Footer Text\", icon_url=\"URL of icon\")\n\n# set timestamp (default is now) accepted types are int, float and datetime\nembed.set_timestamp()\n\n# add fields to embed\nembed.add_embed_field(name=\"Field 1\", value=\"Lorem ipsum\")\nembed.add_embed_field(name=\"Field 2\", value=\"dolor sit\")\n\n# add embed object to webhook\nwebhook.add_embed(embed)\n\nresponse = webhook.execute()\n```\n\n![Image](img/extended_embed.png \"Basic Embed Example Result\")\n\nThis is another example with embedded content\n\n```python\nfrom discord_webhook import DiscordWebhook, DiscordEmbed\n\nwebhook = DiscordWebhook(url=\"your webhook url\", username=\"New Webhook Username\")\n\nembed = DiscordEmbed(title=\"Embed Title\", description=\"Your Embed Description\", color=\"03b2f8\")\nembed.set_author(name=\"Author Name\", url=\"https://github.com/lovvskillz\", icon_url=\"https://avatars0.githubusercontent.com/u/14542790\")\nembed.set_footer(text=\"Embed Footer Text\")\nembed.set_timestamp()\nembed.add_embed_field(name=\"Field 1\", value=\"Lorem ipsum\")\nembed.add_embed_field(name=\"Field 2\", value=\"dolor sit\")\nembed.add_embed_field(name=\"Field 3\", value=\"amet consetetur\")\nembed.add_embed_field(name=\"Field 4\", value=\"sadipscing elitr\")\n\nwebhook.add_embed(embed)\nresponse = webhook.execute()\n```\n\n![Image](img/extended_embed2.png \"Example Embed Result\")\n\nBy Default, the Embed fields are placed side by side. We can arrange them in a new line by setting `inline=False` as follows:\n\n```python\nfrom discord_webhook import DiscordWebhook, DiscordEmbed\n\nwebhook = DiscordWebhook(url=\"your webhook url\", username=\"New Webhook Username\")\n\nembed = DiscordEmbed(\n    title=\"Embed Title\", description=\"Your Embed Description\", color=\"03b2f8\"\n)\nembed.set_author(\n    name=\"Author Name\",\n    url=\"https://github.com/lovvskillz\",\n    icon_url=\"https://avatars0.githubusercontent.com/u/14542790\",\n)\nembed.set_footer(text=\"Embed Footer Text\")\nembed.set_timestamp()\n# Set `inline=False` for the embed field to occupy the whole line\nembed.add_embed_field(name=\"Field 1\", value=\"Lorem ipsum\", inline=False)\nembed.add_embed_field(name=\"Field 2\", value=\"dolor sit\", inline=False)\nembed.add_embed_field(name=\"Field 3\", value=\"amet consetetur\")\nembed.add_embed_field(name=\"Field 4\", value=\"sadipscing elitr\")\n\nwebhook.add_embed(embed)\nresponse = webhook.execute()\n```\n\n![Image](img/extended_embed3.png \"Example Non-Inline Embed Result\")\n\n### Edit Webhook Messages\n\n```python\nfrom discord_webhook import DiscordWebhook\nfrom time import sleep\n\nwebhook = DiscordWebhook(url=\"your webhook url\", content=\"Webhook content before edit\")\nwebhook.execute()\nwebhook.content = \"After Edit\"\nsleep(10)\nwebhook.edit()\n```\n\n### Delete Webhook Messages\n\n```python\nfrom discord_webhook import DiscordWebhook\nfrom time import sleep\n\nwebhook = DiscordWebhook(url=\"your webhook url\", content=\"Webhook Content\")\nwebhook.execute()\nsleep(10)\nwebhook.delete()\n```\n\n### Send Files\n\n```python\nfrom discord_webhook import DiscordWebhook\n\nwebhook = DiscordWebhook(url=\"your webhook url\", username=\"Webhook with files\")\n\n# send two images\nwith open(\"path/to/first/image.jpg\", \"rb\") as f:\n    webhook.add_file(file=f.read(), filename=\"example.jpg\")\nwith open(\"path/to/second/image.jpg\", \"rb\") as f:\n    webhook.add_file(file=f.read(), filename=\"example2.jpg\")\n\nresponse = webhook.execute()\n```\n\n![Image](img/webhook_files.png \"Example Files Result\")\n\nYou can use uploaded attachments in Embeds:\n\n```python\nfrom discord_webhook import DiscordWebhook, DiscordEmbed\n\nwebhook = DiscordWebhook(url=\"your webhook url\")\n\nwith open(\"path/to/image.jpg\", \"rb\") as f:\n    webhook.add_file(file=f.read(), filename=\"example.jpg\")\n\nembed = DiscordEmbed(title=\"Embed Title\", description=\"Your Embed Description\", color=\"03b2f8\")\nembed.set_thumbnail(url=\"attachment://example.jpg\")\n\nwebhook.add_embed(embed)\nresponse = webhook.execute()\n```\n\n### Remove Embeds and Files\n\n```python\nfrom discord_webhook import DiscordWebhook, DiscordEmbed\n\nwebhook = DiscordWebhook(url=\"your webhook url\")\n\nwith open(\"path/to/image.jpg\", \"rb\") as f:\n    webhook.add_file(file=f.read(), filename=\"example.jpg\")\n\nembed = DiscordEmbed(title=\"Embed Title\", description=\"Your Embed Description\", color=\"03b2f8\")\nembed.set_thumbnail(url=\"attachment://example.jpg\")\n\nwebhook.add_embed(embed)\nresponse = webhook.execute(remove_embeds=True)\n# webhook.embeds will be empty after webhook is executed\n# You could also manually call the function webhook.remove_embeds()\n```\n\n`.remove_file()` removes the given file\n\n```python\nfrom discord_webhook import DiscordWebhook\n\nwebhook = DiscordWebhook(url=\"your webhook url\", username=\"Webhook with files\")\n\n# send two images\nwith open(\"path/to/first/image.jpg\", \"rb\") as f:\n    webhook.add_file(file=f.read(), filename=\"example.jpg\")\nwith open(\"path/to/second/image.jpg\", \"rb\") as f:\n    webhook.add_file(file=f.read(), filename=\"example2.jpg\")\n# remove \"example.jpg\"\nwebhook.remove_file(\"example.jpg\")\n# only \"example2.jpg\" is sent to the webhook\nresponse = webhook.execute()\n```\n\n### Allowed Mentions\n\nLook into the [Discord Docs](https://discord.com/developers/docs/resources/channel#allowed-mentions-object) for examples and for more explanation.\n\nThis example would only ping user `123` and `124` but not everyone else.\n\n```python\nfrom discord_webhook import DiscordWebhook\n\ncontent = \"@everyone say hello to our new friends \u003c@123\u003e and \u003c@124\u003e\"\nallowed_mentions = {\n    \"parse\": [\"everyone\"],\n    \"users\": [\"123\", \"124\"]\n}\n\nwebhook = DiscordWebhook(url=\"your webhook url\", content=content, allowed_mentions=allowed_mentions)\nresponse = webhook.execute()\n```\n\n### Use Message Flags\n\nFlags can also be set for messages. Only two are currently supported.\n\n```python\nfrom discord_webhook import DiscordEmbed, DiscordWebhook\nfrom discord_webhook.constants import MessageFlags\n\ncontent = \"Hi.\"\n\n# this message will not trigger push and desktop notifications\nwebhook = DiscordWebhook(url=\"your webhook url\", content=content, flags=MessageFlags.SUPPRESS_NOTIFICATIONS.value)\nresponse = webhook.execute()\n\n# do not include any embeds when serializing this message\nwebhook = DiscordWebhook(url=\"your webhook url\", content=content, flags=MessageFlags.SUPPRESS_EMBEDS.value)\nembed = DiscordEmbed(title=\"Your Title\", description=\"Lorem ipsum dolor sit\", color=\"03b2f8\")\nwebhook.add_embed(embed)\n# even if an embed has been added, it will not appear in the message.\nresponse = webhook.execute()\n```\n\n### Use Proxies\n\n```python\nfrom discord_webhook import DiscordWebhook\n\nproxies = {\n  \"http\": \"http://10.10.1.10:3128\",\n  \"https\": \"http://10.10.1.10:1080\",\n}\nwebhook = DiscordWebhook(url=\"your webhook url\", content=\"Webhook Message\", proxies=proxies)\nresponse = webhook.execute()\n```\nor\n```python\nfrom discord_webhook import DiscordWebhook\n\nproxies = {\n  \"http\": \"http://10.10.1.10:3128\",\n  \"https\": \"http://10.10.1.10:1080\",\n}\nwebhook = DiscordWebhook(url=\"your webhook url\", content=\"Webhook Message\")\nwebhook.set_proxies(proxies)\nresponse = webhook.execute()\n```\n\n### Timeout\n\n```python\nfrom requests.exceptions import Timeout\nfrom discord_webhook import DiscordWebhook, DiscordEmbed\n\n# We will set ridiculously low timeout threshold for testing purposes\nwebhook = DiscordWebhook(url=\"your webhook url\", timeout=0.1)\n\n# You can also set timeout later using\n# webhook.timeout = 0.1\n\nembed = DiscordEmbed(title=\"Embed Title\", description=\"Your Embed Description\", color=\"03b2f8\")\n\nwebhook.add_embed(embed)\n\n# Handle timeout exception\ntry:\n    response = webhook.execute()\nexcept Timeout as err:\n    print(f\"Oops! Connection to Discord timed out: {err}\")\n```\n\n### Async support\nIn order to use the async version, you need to install the package using:\n```\npip install discord-webhook[async]\n```\nExample usage:\n```python\nimport asyncio\nfrom discord_webhook import AsyncDiscordWebhook\n\n\nasync def send_webhook(message):\n    webhook = AsyncDiscordWebhook(url=\"your webhook url\", content=message)\n    await webhook.execute()\n\n\nasync def main():\n    await asyncio.gather(\n        send_webhook(\"Async webhook message 1\"),\n        send_webhook(\"Async webhook message 2\"),\n    )  # sends both messages asynchronously\n\n\nasyncio.run(main())\n```\n\n### Use CLI\n\n```\nusage: discord_webhook [-h] -u URL [URL ...] -c CONTENT [--username USERNAME]\n                       [--avatar_url AVATAR_URL]\n\nTrigger discord webhook(s).\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -u URL [URL ...], --url URL [URL ...]\n                        Webhook(s) url(s)\n  -c CONTENT, --content CONTENT\n                        Message content\n  --username USERNAME   override the default username of the webhook\n  --avatar_url AVATAR_URL\n                        override the default avatar of the webhook\n```\n\n## Development\n\n### Dev Setup\nThis project uses [Poetry](https://python-poetry.org/docs/) for dependency management and packaging.\n\nInstall Poetry and add Poetry to [Path](https://python-poetry.org/docs/#installation).\n\n**Debian / Ubuntu / Mac**\n\n`curl -sSL https://install.python-poetry.org | python3 -`\n\n**Windows**\n\nopen powershell and run: `(Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | py -`\n\nInstall dependencies: `poetry install`\n\nInstall the defined pre-commit hooks: `poetry run pre-commit install`\n\nActivate the virtualenv: `poetry shell`","funding_links":[],"categories":["Python"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flovvskillz%2Fpython-discord-webhook","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flovvskillz%2Fpython-discord-webhook","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flovvskillz%2Fpython-discord-webhook/lists"}