Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
OBS Plugin to send a webhook message to Discord when you start streaming (requires discord-webhook to be installed)
import obspython
from discord_webhook import DiscordWebhook
webhookUrl = ""
content = ""
enabled = False
def frontend_event_handler(data):
if data == obspython.OBS_FRONTEND_EVENT_STREAMING_STARTED and enabled:
webhook = DiscordWebhook(url=webhookUrl, content=content)
webhook.execute()
def validate_webhook_url(url):
return url.startswith("https://discord.com/api/webhooks/")
def script_update(settings):
global webhookUrl
global enabled
global content
webhookUrl = obspython.obs_data_get_string(settings, "webhookUrl").strip()
content = obspython.obs_data_get_string(settings, "content")
enabled = validate_webhook_url(webhookUrl)
if not enabled:
print("Invalid Webhook URL : {}".format(webhookUrl))
def script_description():
return "Sends a Webhook Request to post a message on a Discord channel when you start streaming"
def script_properties():
props = obspython.obs_properties_create()
obspython.obs_properties_add_text(props,
"webhookUrl",
"Webhook URL",
obspython.OBS_TEXT_DEFAULT)
obspython.obs_properties_add_text(props,
"content",
"Content",
obspython.OBS_TEXT_MULTILINE)
return props
obspython.obs_frontend_add_event_callback(frontend_event_handler)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment