Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import urllib.request
- import random
- import json
- try:
- from tkinter import Tk, messagebox
- except ImportError:
- tk = False
- else:
- tk = True
- root = Tk()
- root.withdraw()
- # Discord Markdown formatting works here!
- # Keep this in the same order as the WEBHOOKS below if you want -
- # webhook/channel-specific messages.
- # If you want the same message across all webhooks, just use one message.
- MESSAGES = [
- "MESSAGE1",
- ]
- # If you have more than one message and want a random one to be sent, -
- # set this to True, else set it to False.
- randomise = False
- # Right click channel > Edit Channel > Webhooks
- # Create webhook or edit existing, copy URL
- # Add another line inside the brackets to announce to extra channels
- # "WEBHOOK URL",
- # note the trailing comma
- WEBHOOKS = [
- "WEBHOOK URL",
- ]
- statuses = []
- headers = {'Content-Type': 'application/json',
- 'User-Agent': "Stream Announcer"}
- for ind, hook in enumerate(WEBHOOKS):
- if len(MESSAGES) == 1:
- message = MESSAGES[0]
- elif randomise:
- message = random.choice(MESSAGES)
- elif len(MESSAGES) == len(WEBHOOKS):
- message = MESSAGES[ind]
- else:
- if tk:
- messagebox.showerror('Error',
- 'Mismatching message and webhook counts.\n'
- 'Fix that or set `randomise` to `True`.')
- else:
- print('Mismatching message and webhook counts.\n'
- 'Fix that or set `randomise` to `True`.')
- input('Press RETURN or close the window to exit.')
- raise SystemExit(1)
- data = json.dumps({'content': message}).encode('utf-8')
- req = urllib.request.Request(hook, data=data, headers=headers, method='POST')
- with urllib.request.urlopen(req) as r:
- statuses.append(r.getcode())
- print(('Status code: {}\n' * len(statuses)).format(*statuses))
- input('Press RETURN or close the window to exit.')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement