benjaminvr

Python - DiscordNotifier class for webhook

Jul 26th, 2021
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.70 KB | None | 0 0
  1. import requests
  2. from conf import staticConfigs
  3.  
  4. class DiscordNotifier:
  5.     def __init__(self):
  6.         self.configs = staticConfigs()
  7.         self.webhook_url = self.configs.discord_webhook_url
  8.         self.bot_username = "Notifier"
  9.         self.data_struct = {
  10.             "content": "",
  11.             "username": self.bot_username
  12.         }
  13.  
  14.     def _PostToWebhook(self):
  15.         res = requests.post(self.webhook_url, json=self.data_struct)
  16.         try:
  17.             res.raise_for_status()
  18.         except Exception as e:
  19.             return False
  20.         else:
  21.             return True
  22.  
  23.     def Notify(self, message):
  24.         self.data_struct["content"] = message
  25.         return self._PostToWebhook()
Advertisement
Add Comment
Please, Sign In to add comment