A minimal Discord API webhooks wrapper for sending messages to a Discord channel
Project description
discord_notify
discord_notify is a minimal Discord API webhooks wrapper for easily sending messages to a Discord channel.
Use Cases
- Remote logging for lengthy Python scripts, such as:
- Providing notifications during neural network training (e.g. logging validation accuracy after each training epoch)
- Providing notifications on the status of a Python web server
- Regularly displaying information on a Discord channel without configuring a bot
Installation
pip install discord_notify
Usage
First, you'll need to create a new webhook for one of your Discord channels (Edit Channel > Integrations > Webhooks).
Then you can use this webhook in your code by creating an instance of the Notifier class and using the webhook's URL:
import discord_notify as dn
notifier = dn.Notifier(URL)
Sending Messages Once
Messages can be sent through the webhook by using the send method of the Notifier class.
notifier.send("Hello, world!", print_message=False)
print_messageindicates whether or not the provided message should be printed to the console. It defaults toTrue.
Sending Messages Repeatedly
The send_repeat method can be used to send messages over a regular interval of time.
x = 0
notifier.send_repeat(lambda: x, 1.5, print_message=False)
while x < 100000:
x += 0.0001
The first parameter is a callable that returns the value to send, and the second parameter is the number of seconds to wait between webhook executions.
The method's daemon parameter can be set to False, forcing the timer thread to be stopped manually with the stop_repeat method. This requires a timer_id which is returned from send_repeat:
x = 0
timer_id = notifier.send_repeat(
lambda: x,
1.5,
print_message=False,
daemon=False
)
while x < 100000:
x += 0.0001
if x > 10000:
notifier.stop_repeat(timer_id)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file discord_notify-1.0.0.tar.gz.
File metadata
- Download URL: discord_notify-1.0.0.tar.gz
- Upload date:
- Size: 3.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
76486cb62c2885ddad55e83b51225801efc0d57195106fd0f8dbf31958780959
|
|
| MD5 |
91b28a9aa4d1d41f235825f1691f5c7e
|
|
| BLAKE2b-256 |
47fd49b17d88b25c18786edb832d53b72e717d1727c9e1e820fc9fed82a5eae0
|
File details
Details for the file discord_notify-1.0.0-py3-none-any.whl.
File metadata
- Download URL: discord_notify-1.0.0-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
847f92d1ead1437804649b4767c04ef7b7e69b618baa5742b607391819549b88
|
|
| MD5 |
ec5fefb13449d62633a732974ebfc33b
|
|
| BLAKE2b-256 |
a295c54d8d393cda9fb64a4d4d2d9c67a8d596b31fd798cc04193e2c54a81ee7
|