Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

DiscordAlerts-0.1.1.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

DiscordAlerts-0.1.1-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file DiscordAlerts-0.1.1.tar.gz.

File metadata

  • Download URL: DiscordAlerts-0.1.1.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for DiscordAlerts-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ead635c142f18e94d74ed3986edb9c89148021d1004a4c6fb2470fad63104b2b
MD5 c141854be18f5efbcf24de213c745c62
BLAKE2b-256 c9f7daba2ad56dbc0151e60561e951f4ce3abafb34e2156899360bd13fcb5433

See more details on using hashes here.

File details

Details for the file DiscordAlerts-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: DiscordAlerts-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for DiscordAlerts-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ba917f1c1c3a20fcd1953fb236b1fb147f83f56fcdbbf5e6e0ca611982294bbe
MD5 0f305bace721f29a11aa938ecdb9736c
BLAKE2b-256 018eb0f087090dd6487b696c2e0626f90a4ac153b60fc9d3cf5f84ea8c8bd797

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page