discord-webhook


Namediscord-webhook JSON
Version 1.3.1 PyPI version JSON
download
home_pagehttps://github.com/lovvskillz/python-discord-webhook
SummaryEasily send Discord webhooks with Python
upload_time2024-01-31 17:23:14
maintainer
docs_urlNone
authorlovvskillz
requires_python>=3.10,<4.0
licenseMIT
keywords discord webhook
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Python Discord webhook

[![GitHub license](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://raw.githubusercontent.com/lovvskillz/python-discord-webhook/master/LICENSE)
[![PyPI version](https://badge.fury.io/py/discord-webhook.svg)](https://badge.fury.io/py/discord-webhook)
[![Downloads](https://pepy.tech/badge/discord-webhook)](https://pepy.tech/project/discord-webhook)

Easily send Discord webhooks with Python (also has [async support](#async-support))

## Install

Install via pip:
```
pip install discord-webhook
```

## Examples

* [Basic Webhook](#basic-webhook)
* [Create Multiple Instances / Use multiple URLs](#create-multiple-instances)
* [Get Webhook by ID](#get-webhook-by-id)
* [Send Webhook to thread](#send-webhook-to-thread)
* [Manage Being Rate Limited](#manage-being-rate-limited)
* [Embedded Content](#webhook-with-embedded-content)
* [Edit Webhook Message](#edit-webhook-messages)
* [Delete Webhook Message](#delete-webhook-messages)
* [Send Files](#send-files)
* [Remove Embeds and Files](#remove-embeds-and-files)
* [Allowed Mentions](#allowed-mentions)
* [Use Proxies](#use-proxies)
* [Timeout](#timeout)
* [Async Support](#async-support)

### Basic Webhook

```python
from discord_webhook import DiscordWebhook

webhook = DiscordWebhook(url="your webhook url", content="Webhook Message")
response = webhook.execute()
```

### Create multiple instances
If you want to use multiple URLs you need to create multiple instances.

```python
from discord_webhook import DiscordWebhook

# you can provide any kwargs except url
webhook1, webhook2 = DiscordWebhook.create_batch(urls=["first url", "second url"], content="Webhook Message")
response1 = webhook1.execute()
response2 = webhook2.execute()
```
![Image](img/multiple_urls.png "Multiple Urls Result")

### Get Webhook by ID
You can access a webhook that has already been sent by providing the ID.

````python
from discord_webhook import DiscordWebhook

webhook = DiscordWebhook(url="your webhook url", id="your webhook message id")
# now you could delete or edit the webhook
# ...
````
### Send Webhook to thread
You 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`.
```python
from discord_webhook import DiscordWebhook

# send to an existing thread
webhook = DiscordWebhook(url="your webhook url", thread_id="the thread id")
webhook.execute()

# create a new thread in a forum channel
webhook = DiscordWebhook(url="your webhook url", thread_name="some-thread-name")
webhook.execute()
```

### Manage being Rate Limited

```python
from discord_webhook import DiscordWebhook

# if rate_limit_retry is True then in the event that you are being rate 
# limited by Discord your webhook will automatically be sent once the 
# rate limit has been lifted
webhook = DiscordWebhook(url="your webhook url", rate_limit_retry=True, content="Webhook Message")
response = webhook.execute()
```

![Image](img/basic_webhook.png "Basic Example Result")

### Webhook with Embedded Content

```python
from discord_webhook import DiscordWebhook, DiscordEmbed

webhook = DiscordWebhook(url="your webhook url")

# create embed object for webhook
# you can set the color as a decimal (color=242424) or hex (color="03b2f8") number
embed = DiscordEmbed(title="Your Title", description="Lorem ipsum dolor sit", color="03b2f8")

# add embed object to webhook
webhook.add_embed(embed)

response = webhook.execute()
```

![Image](img/simple_embed.png "Basic Embed Example Result")

```python
from discord_webhook import DiscordWebhook, DiscordEmbed

webhook = DiscordWebhook(url="your webhook url")

# create embed object for webhook
embed = DiscordEmbed(title="Your Title", description="Lorem ipsum dolor sit", color="03b2f8")

# set author
embed.set_author(name="Author Name", url="author url", icon_url="author icon url")

# set image
embed.set_image(url="your image url")

# set thumbnail
embed.set_thumbnail(url="your thumbnail url")

# set footer
embed.set_footer(text="Embed Footer Text", icon_url="URL of icon")

# set timestamp (default is now) accepted types are int, float and datetime
embed.set_timestamp()

# add fields to embed
embed.add_embed_field(name="Field 1", value="Lorem ipsum")
embed.add_embed_field(name="Field 2", value="dolor sit")

# add embed object to webhook
webhook.add_embed(embed)

response = webhook.execute()
```

![Image](img/extended_embed.png "Basic Embed Example Result")

This is another example with embedded content

```python
from discord_webhook import DiscordWebhook, DiscordEmbed

webhook = DiscordWebhook(url="your webhook url", username="New Webhook Username")

embed = DiscordEmbed(title="Embed Title", description="Your Embed Description", color="03b2f8")
embed.set_author(name="Author Name", url="https://github.com/lovvskillz", icon_url="https://avatars0.githubusercontent.com/u/14542790")
embed.set_footer(text="Embed Footer Text")
embed.set_timestamp()
embed.add_embed_field(name="Field 1", value="Lorem ipsum")
embed.add_embed_field(name="Field 2", value="dolor sit")
embed.add_embed_field(name="Field 3", value="amet consetetur")
embed.add_embed_field(name="Field 4", value="sadipscing elitr")

webhook.add_embed(embed)
response = webhook.execute()
```

![Image](img/extended_embed2.png "Example Embed Result")

By Default, the Embed fields are placed side by side. We can arrange them in a new line by setting `inline=False` as follows:

```python
from discord_webhook import DiscordWebhook, DiscordEmbed

webhook = DiscordWebhook(url="your webhook url", username="New Webhook Username")

embed = DiscordEmbed(
    title="Embed Title", description="Your Embed Description", color="03b2f8"
)
embed.set_author(
    name="Author Name",
    url="https://github.com/lovvskillz",
    icon_url="https://avatars0.githubusercontent.com/u/14542790",
)
embed.set_footer(text="Embed Footer Text")
embed.set_timestamp()
# Set `inline=False` for the embed field to occupy the whole line
embed.add_embed_field(name="Field 1", value="Lorem ipsum", inline=False)
embed.add_embed_field(name="Field 2", value="dolor sit", inline=False)
embed.add_embed_field(name="Field 3", value="amet consetetur")
embed.add_embed_field(name="Field 4", value="sadipscing elitr")

webhook.add_embed(embed)
response = webhook.execute()
```

![Image](img/extended_embed3.png "Example Non-Inline Embed Result")

### Edit Webhook Messages

```python
from discord_webhook import DiscordWebhook
from time import sleep

webhook = DiscordWebhook(url="your webhook url", content="Webhook content before edit")
webhook.execute()
webhook.content = "After Edit"
sleep(10)
webhook.edit()
```

### Delete Webhook Messages

```python
from discord_webhook import DiscordWebhook
from time import sleep

webhook = DiscordWebhook(url="your webhook url", content="Webhook Content")
webhook.execute()
sleep(10)
webhook.delete()
```

### Send Files

```python
from discord_webhook import DiscordWebhook

webhook = DiscordWebhook(url="your webhook url", username="Webhook with files")

# send two images
with open("path/to/first/image.jpg", "rb") as f:
    webhook.add_file(file=f.read(), filename="example.jpg")
with open("path/to/second/image.jpg", "rb") as f:
    webhook.add_file(file=f.read(), filename="example2.jpg")

response = webhook.execute()
```

![Image](img/webhook_files.png "Example Files Result")

You can use uploaded attachments in Embeds:

```python
from discord_webhook import DiscordWebhook, DiscordEmbed

webhook = DiscordWebhook(url="your webhook url")

with open("path/to/image.jpg", "rb") as f:
    webhook.add_file(file=f.read(), filename="example.jpg")

embed = DiscordEmbed(title="Embed Title", description="Your Embed Description", color="03b2f8")
embed.set_thumbnail(url="attachment://example.jpg")

webhook.add_embed(embed)
response = webhook.execute()
```

### Remove Embeds and Files

```python
from discord_webhook import DiscordWebhook, DiscordEmbed

webhook = DiscordWebhook(url="your webhook url")

with open("path/to/image.jpg", "rb") as f:
    webhook.add_file(file=f.read(), filename="example.jpg")

embed = DiscordEmbed(title="Embed Title", description="Your Embed Description", color="03b2f8")
embed.set_thumbnail(url="attachment://example.jpg")

webhook.add_embed(embed)
response = webhook.execute(remove_embeds=True)
# webhook.embeds will be empty after webhook is executed
# You could also manually call the function webhook.remove_embeds()
```

`.remove_file()` removes the given file

```python
from discord_webhook import DiscordWebhook

webhook = DiscordWebhook(url="your webhook url", username="Webhook with files")

# send two images
with open("path/to/first/image.jpg", "rb") as f:
    webhook.add_file(file=f.read(), filename="example.jpg")
with open("path/to/second/image.jpg", "rb") as f:
    webhook.add_file(file=f.read(), filename="example2.jpg")
# remove "example.jpg"
webhook.remove_file("example.jpg")
# only "example2.jpg" is sent to the webhook
response = webhook.execute()
```

### Allowed Mentions

Look into the [Discord Docs](https://discord.com/developers/docs/resources/channel#allowed-mentions-object) for examples and for more explanation

This example would only ping user `123` and `124` but not everyone else.

```python
from discord_webhook import DiscordWebhook

content = "@everyone say hello to our new friends <@123> and <@124>"
allowed_mentions = {
    "parse": ["everyone"],
    "users": ["123", "124"]
}

webhook = DiscordWebhook(url="your webhook url", content=content, allowed_mentions=allowed_mentions)
response = webhook.execute()
```

### Use Proxies

```python
from discord_webhook import DiscordWebhook

proxies = {
  "http": "http://10.10.1.10:3128",
  "https": "http://10.10.1.10:1080",
}
webhook = DiscordWebhook(url="your webhook url", content="Webhook Message", proxies=proxies)
response = webhook.execute()
```
or
```python
from discord_webhook import DiscordWebhook

proxies = {
  "http": "http://10.10.1.10:3128",
  "https": "http://10.10.1.10:1080",
}
webhook = DiscordWebhook(url="your webhook url", content="Webhook Message")
webhook.set_proxies(proxies)
response = webhook.execute()
```

### Timeout

```python
from requests.exceptions import Timeout
from discord_webhook import DiscordWebhook, DiscordEmbed

# We will set ridiculously low timeout threshold for testing purposes
webhook = DiscordWebhook(url="your webhook url", timeout=0.1)

# You can also set timeout later using
# webhook.timeout = 0.1

embed = DiscordEmbed(title="Embed Title", description="Your Embed Description", color="03b2f8")

webhook.add_embed(embed)

# Handle timeout exception
try:
    response = webhook.execute()
except Timeout as err:
    print(f"Oops! Connection to Discord timed out: {err}")
```

### Async support
In order to use the async version, you need to install the package using:
```
pip install discord-webhook[async]
```
Example usage:
```python
import asyncio
from discord_webhook import AsyncDiscordWebhook


async def send_webhook(message):
    webhook = AsyncDiscordWebhook(url="your webhook url", content=message)
    await webhook.execute()


async def main():
    await asyncio.gather(
        send_webhook("Async webhook message 1"),
        send_webhook("Async webhook message 2"),
    )  # sends both messages asynchronously


asyncio.run(main())
```

### Use CLI

```
usage: discord_webhook [-h] -u URL [URL ...] -c CONTENT [--username USERNAME]
                       [--avatar_url AVATAR_URL]

Trigger discord webhook(s).

optional arguments:
  -h, --help            show this help message and exit
  -u URL [URL ...], --url URL [URL ...]
                        Webhook(s) url(s)
  -c CONTENT, --content CONTENT
                        Message content
  --username USERNAME   override the default username of the webhook
  --avatar_url AVATAR_URL
                        override the default avatar of the webhook
```

## Development

### Dev Setup
This project uses [Poetry](https://python-poetry.org/docs/) for dependency management and packaging.

Install Poetry and add Poetry to [Path](https://python-poetry.org/docs/#installation).

**Debian / Ubuntu / Mac**

`curl -sSL https://install.python-poetry.org | python3 -`

**Windows**

open powershell and run: `(Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | py -`

Install dependencies: `poetry install`

Install the defined pre-commit hooks: `poetry run pre-commit install`

Activate the virtualenv: `poetry shell`
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/lovvskillz/python-discord-webhook",
    "name": "discord-webhook",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.10,<4.0",
    "maintainer_email": "",
    "keywords": "discord,webhook",
    "author": "lovvskillz",
    "author_email": "14542790+lovvskillz@users.noreply.github.com",
    "download_url": "https://files.pythonhosted.org/packages/e8/e6/660b07356a15d98787d893f879efc404eb15176312d457f2f6f7090acd32/discord_webhook-1.3.1.tar.gz",
    "platform": null,
    "description": "# 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 thread](#send-webhook-to-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 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 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 <@123> and <@124>\"\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 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`",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Easily send Discord webhooks with Python",
    "version": "1.3.1",
    "project_urls": {
        "Homepage": "https://github.com/lovvskillz/python-discord-webhook",
        "Repository": "https://github.com/lovvskillz/python-discord-webhook"
    },
    "split_keywords": [
        "discord",
        "webhook"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "92e2eed83ebc8d88da0930143a6dd1d0ba0b6deba1fd91b956f21c23a2608510",
                "md5": "62fd1e167f7d8e97f5520a83dc76215c",
                "sha256": "ede07028316de76d24eb811836e2b818b2017510da786777adcb0d5970e7af79"
            },
            "downloads": -1,
            "filename": "discord_webhook-1.3.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "62fd1e167f7d8e97f5520a83dc76215c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10,<4.0",
            "size": 13206,
            "upload_time": "2024-01-31T17:23:12",
            "upload_time_iso_8601": "2024-01-31T17:23:12.424593Z",
            "url": "https://files.pythonhosted.org/packages/92/e2/eed83ebc8d88da0930143a6dd1d0ba0b6deba1fd91b956f21c23a2608510/discord_webhook-1.3.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e8e6660b07356a15d98787d893f879efc404eb15176312d457f2f6f7090acd32",
                "md5": "10e043e6c7f0895183b3d15280ce9499",
                "sha256": "ee3e0f3ea4f3dc8dc42be91f75b894a01624c6c13fea28e23ebcf9a6c9a304f7"
            },
            "downloads": -1,
            "filename": "discord_webhook-1.3.1.tar.gz",
            "has_sig": false,
            "md5_digest": "10e043e6c7f0895183b3d15280ce9499",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10,<4.0",
            "size": 11715,
            "upload_time": "2024-01-31T17:23:14",
            "upload_time_iso_8601": "2024-01-31T17:23:14.463463Z",
            "url": "https://files.pythonhosted.org/packages/e8/e6/660b07356a15d98787d893f879efc404eb15176312d457f2f6f7090acd32/discord_webhook-1.3.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-31 17:23:14",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "lovvskillz",
    "github_project": "python-discord-webhook",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "discord-webhook"
}
        
Elapsed time: 0.18585s