Skip to main content

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

Metadata

Release files for DiscordAlerts 0.1.1

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

Source distribution (sdist)

Source distribution for DiscordAlerts 0.1.1
File Size Uploaded Provenance Actions
DiscordAlerts-0.1.1.tar.gz 4.5 kB Without provenance Details for DiscordAlerts-0.1.1.tar.gz

Built distribution (wheel)

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

Total release size: 10.7 kB

Release files / DiscordAlerts-0.1.1.tar.gz

Download URL DiscordAlerts-0.1.1.tar.gz
Size 4.5 kB
Tags Source
SHA-256 checksum
How to use checksums
ead635c142f18e94d74ed3986edb9c89148021d1004a4c6fb2470fad63104b2b
BLAKE2b-256 checksum
How to use checksums
c9f7daba2ad56dbc0151e60561e951f4ce3abafb34e2156899360bd13fcb5433
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Release files / DiscordAlerts-0.1.1-py3-none-any.whl

Download URL DiscordAlerts-0.1.1-py3-none-any.whl
Size 6.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ba917f1c1c3a20fcd1953fb236b1fb147f83f56fcdbbf5e6e0ca611982294bbe
BLAKE2b-256 checksum
How to use checksums
018eb0f087090dd6487b696c2e0626f90a4ac153b60fc9d3cf5f84ea8c8bd797
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Security for DiscordAlerts 0.1.1

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.1 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