Skip to main content

RedWebhook

GitHub license

Install

Install using pip:

- pip install RedWebhook - pip install -U RedWebhook - python -m pip install -U RedWebhook

Examples

basic webhook

from RedWebhook import RedWebhook

webhook = RedWebhook(url="", content="Webhook Message")
response = webhook.execute()

manage discord rate limit

from RedWebhook import RedWebhook

webhook = RedWebhook(
    url='<your_webhook_url_here>',
    rate_limit_retry=True,
    content='Example'
)

response = webhook.execute()

multiple webhook urls

from RedWebhook import RedWebhook

webhooks = ['<webhook_url_1>', '<webhook_url_2>']

webhook = RedWebhook(
    url=webhooks,
    content='Webhook'
)

response = webhook.execute()

embedded webhook

from RedWebhook import RedWebhook, DiscordEmbed

webhook = RedWebhook(url='<your_webhook_url_here>')

# create embed objects for webhook
embed = DiscordEmbed(
    title='<your_title>',
    description='<your_description>',
    color='<your_color>'
)

# set author
embed.set_author(
    name='<author>',
    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_thumbnail(
    text='<your_footer>'
)

# set timestamp (default is now)
embed.set_timestamp()

# add fields to the embed
embed.add_embed_field(
    name='<field_1>',
    value='<field_description>'
)
embed.add_embed_field(
    name='<field_2>',
    value='<field_description>'
)

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

response = webhook.execute()

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

from RedWebhook import RedWebhook, DiscordEmbed

webhook = RedWebhook(url='<your_webhook_url_here>')

embed = DiscordEmbed(
    title='<your_title>',
    description='<your_description>',
    color='<your_color>'
)
embed.set_footer(
    text='<your_footer>'
)
embed.set_timestamp()
# set `inline=False` for the embed field to come in the whole line
embed.add_embed_field(
    name='<field_1>',
    value='<field_description>',
    inline=False
)
embed.add_embed_field(
    name='<field_2>',
    value='<field_description>',
    inline=False
)
embed.add_embed_field(
    name='<field_3>',
    value='<field_description>'
)
embed.add_embed_field(
    name='<field_3>',
    value='<field_description>'
)

edit webhook message

from RedWebhook import RedWebhook
from time import sleep

webhook = RedWebhook(
    url='<your_webhook_url_here>',
    content='Before edit'
)

sent_webhook = webhook.execute()

webhook.content = 'After edit'

sleep(10)

sent_webhook = webhook.edit(sent_webhook)

delete webhook messages

from RedWebhook import RedWebhook
from time import sleep

webhook = RedWebhook(
    url='<your_webhook_url_here>',
    content='Before edit'
)

sent_webhook = webhook.execute()

sleep(10)

webhook.delete(sent_webhook)

send files

from RedWebhook import RedWebhook

webhook = RedWebhook(
    url='<your_webhook_url_here>',
    username='RedWebhook with files'
)

with open('path/to/first/image.jpg', 'rb') as f:
    webhook.add_file(file=f.read(), filename='image1.jpg')
with open("path/to/second/image.jpg", "rb") as f:
    webhook.add_file(file=f.read(), filename='image2.jpg')
    
response = webhook.execute()

You can also upload embedded attachments:

from RedWebhook import RedWebhook, DiscordEmbed

webhook = RedWebhook(
    url='<your_webhook_url_here>'
)

with open('path/to/image.jpg', 'rb') as f:
    webhook.add_file(file=f.read(), filename='attach.jpg')
    
embed = DiscordEmbed(
    title='<your_embed_title>',
    description='<your_embed_description>',
    color=0x2f3136
)

embed.set_thumbnail(url='attachment://attach.jpg')

webhook.add_embed(embed)

response = webhook.execute()

remove embeds and files

from RedWebhook import RedWebhook, DiscordEmbed

webhook = RedWebhook(
    url='<your_webhook_url_here>'
)

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

embed = DiscordEmbed(
    title='<your_embed_title>',
    description='<your_embed_description>',
    color=0x2f3136
)

embed.set_thumbnail(url='attachment://attach.jpg')

webhook.add_embed(embed)

response = webhook.execute(remove_embeds=True, remove_files=True)
# webhook.files and webhook.embeds will be empty after webhook is executed
# You could also manually call the functions webhook.remove_files() and webhook.remove_embeds()

.remove_file() removes the given file:

from RedWebhook import RedWebhook

webhook = RedWebhook(
    url='<your_webhook_url_here>',
    username='Webhook files'
)

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

# remove 'image1.jpg'
webhook.remove_file('image1.jpg')

# only 'image2.jpg' is sent to the webhook
response = webhook.execute()

allowed mentions

Look into the Discord Documentation for examples and explanation

This example will only ping user_id_1 and user_id_2, no one else

from RedWebhook import RedWebhook

content = '@everyone say hello to our friends <@user_id_1> and <@user_id_2>'

allowed_mentions = {
    'users': ['user_id_1', 'user_id_2]
}

webhook = RedWebhook(
    url='<your_webhook_url_here>',
    content=content,
    allowed_mentions=allowed_mentions
)

response = webhook.execute()

use proxies

from RedWebhook import RedWebhook

proxies = {
    'http': 'http://11.11.1.11:6969',
    'https': 'https://11.11.1.11:0420'
}

webhook = RedWebhook(
    url='<your_webhook_url_here>',
    content='Webhook',
    proxies=proxies
)

response = webhook.execute()

or

from RedWebhook import RedWebhook

proxies = {
    'http': 'http://11.11.1.11:6969',
    'https': 'https://11.11.1.11:0420'
}

webhook = RedWebhook(
    url='<your_webhook_url_here>',
    content='Webhook'
)

webhook.set_proxies(proxies)

response = webhook.execute()

use cli

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

Trigger Red Webhooks

optional arguments:
    -h, --help                                  show this help message and exit
    -u URL [URL ...], --url URL [URL ...]       webhook url/urls
    -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

timeout

from requests.exceptions import Timeout
from RedWebhook import RedWebhook, DiscordEmbed

# we will set ridiculously low timeout threshold for testing purposes
webhook = RedWebhook(
    url='<your_webhook_url_here>',
    timeout=0.2,
)

# you can also set timeout later using
# webhook.timeout = 0.2

embed = DiscordEmbed(
    title='<embed_title>',
    description='<embed_description>',
    color=0x2f3136
)

webhook.add_embed(embed)

# handle timeout exceptions
try:
    response = webhook.execute()
except Timeout as err:
    print(f'Beep Boop, Connection to Discord timed out: \n{err}')

Metadata

Release files for RedWebhook 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for RedWebhook 0.1.0
File Size Uploaded Provenance Actions
RedWebhook-0.1.0.tar.gz 10.6 kB Without provenance Details for RedWebhook-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for RedWebhook 0.1.0
File Interpreter ABI Platform Actions
RedWebhook-0.1.0-py3-none-any.whl Python 3 none any Details for RedWebhook-0.1.0-py3-none-any.whl

Total release size: 20.3 kB

Release files / RedWebhook-0.1.0.tar.gz

Download URL RedWebhook-0.1.0.tar.gz
Size 10.6 kB
Tags Source
SHA-256 checksum
How to use checksums
d13b00d18e70bad867a6b94c5b5835001c2d359aea46ec95ab151f1497f3041f
BLAKE2b-256 checksum
How to use checksums
443ad8839851fd893dfc2def1735ff157ad6cf7013520a3ce65c1d6b677d740b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.6.0 importlib_metadata/4.8.1 pkginfo/1.8.0 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.6.0

Release files / RedWebhook-0.1.0-py3-none-any.whl

Download URL RedWebhook-0.1.0-py3-none-any.whl
Size 9.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
18d59aa126ba1006e2f6722fdfc9bb11dc89b4443b6d0b994bd21cb718758f37
BLAKE2b-256 checksum
How to use checksums
1caac4ecde2fe3ccd31ad0efe36f1a0b4ea0607d62cf5a49db260b442a98ab5f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.6.0 importlib_metadata/4.8.1 pkginfo/1.8.0 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.6.0

Security for RedWebhook 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page