Package for Alerts on Discord
Project description
DiscordAlerts Documentation
Table of Contents
Introduction
Welcome to the DiscordAlerts
documentation. This document provides information on how to use the DiscordAlerts
package.
Simple Usage
To implement an alert to one function, you need to call a DiscordAlert
object and build this object with your Discord hook. Look at the example below:
from discord_alert.discord_alert import DiscordAlert
from alerts.alerts import alert
hook = DiscordAlert(hook="Your URL hook here")
@alert(hook=hook, custom_msg="You can add a custom message here")
def add(x, y):
return x + y
Sub-modules
alerts
alert(hook: DiscordAlert, custom_msg='')
Decorator function for error handling and sending alerts via webhook.
This function takes a DiscordAlert object and an optional custom message as arguments. It returns a decorator function that wraps another function and handles any exceptions that occur during its execution. If an exception occurs, it sends an alert via a webhook using the DiscordAlert object.
Args:
hook
: An instance of the DiscordAlert class representing a webhook URL.custom_msg
: An optional custom message to be included in the alert.
Returns:
A callable wrapper function.
Example Usage:
@alert(hook=DiscordAlert(hook="webhook_url"), custom_msg="Custom message: ")
def my_function():
# Code to be executed
pass
my_function()
Module discord_alert
Class DiscordAlert
This class represents a Discord alert and provides a method to send alert messages to a Discord webhook.
Example Usage
# Create a DiscordAlert object
alert = DiscordAlert(hook="Your Hook")
# Send an alert message
alert.send_alert("Alert Title", "Alert Message", 0x00ff00, "thumbnail_url")
Attributes
hook
: The webhook URL for sending the alert message.
Method send_alert(title: str, message: str, color: int, thumbnail_url: str) -> bool
Sends an alert message to the Discord webhook.
Args:
title (str)
: The title of the alert message.message (str)
: The message content of the alert.color (int)
: The color of the alert message.thumbnail_url (str)
: The URL of the thumbnail image for the alert.
Returns:
bool
: True if the alert message was successfully sent, False otherwise.
def send_alert(
self, title: str, message: str, color: int, thumbnail_url: str
) -> bool:
"""
Sends an alert message to the Discord webhook.
Args:
title (str): The title of the alert message.
message (str): The message content of the alert.
color (int): The color of the alert message.
thumbnail_url (str): The URL of the thumbnail image for the alert.
Returns:
bool: True if the alert message was successfully sent, False otherwise.
"""
embeds = [
{
"title": title,
"description": message,
"color": color,
"thumbnail": {"url": thumbnail_url},
},
]
try:
webhook = DiscordWebhook(url=self.hook, embeds=embeds)
webhook.execute()
return True
except Exception:
return False
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
Hashes for DiscordAlerts-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba917f1c1c3a20fcd1953fb236b1fb147f83f56fcdbbf5e6e0ca611982294bbe |
|
MD5 | 0f305bace721f29a11aa938ecdb9736c |
|
BLAKE2b-256 | 018eb0f087090dd6487b696c2e0626f90a4ac153b60fc9d3cf5f84ea8c8bd797 |