This is a simple python script to interface a discord chat bot with OBS via a local websocket (WSS). It can control scenes and sources, test user roles, activate or deactivate sources, and send Discord messages.
This script is meant for use with a small, private Discord group.
This script is meant to run locally. Any security is your responsibility.
The bot monitors Discord chat and changes source activation based on the first word in messages.
Uses can include:
This script is intended to run locally in a terminal. Essentially, OBS websocket will never touch the internet. There’s no reason you couldn’t extend this to run on a server if you wanted to set that all up.
Requires Python and the discordpy and obs-web-socket-py python libraries.
Bring your own Discord Bot and invite it into a server with text chat.
The Discord bot requires message read and write permissions (a.k.a. Message Content Intent).
Add OBS WSS info and Discord bot key to settings.json. This information should remain SECURE.
Add any text commands you want to monitor to triggers.json.
Required Parameters
Source Control Parameters
These parameters are required to control Sources. Remove them to switch scenes instead.
Optional Parameters
Make sure your bot is in Discord and you have OBS up with WSS enabled.
Run obs_discord_bot.py in terminal.
python3 obs_discord_bot.py
Run the script. Once it establishes a WSS connection, you’ll begin to get OBS debug updates in the terminal.
Click the source you want to control.
Then, look in the debug messages for sceneItemID.
DEBUG:obswebsocket.core:Got event: {'d': {'eventData': {'sceneItemId': <<THIS ONE>>, 'sceneName': '...', 'sceneUuid': '...'}, 'eventIntent': ..., 'eventType': 'SceneItemSelected'}, 'op': ...}
This trigger activates a Source when anyone types “/pie” in Discord chat.
{
"/pie": {
"scene": "Scene",
"id": 42,
"command": "activate"
}
}
This trigger switches to “New_Scene” when a “Server Admin” or higher types “/switch” in Discord chat.
{
"/switch": {
"scene": "New_Scene",
"min_user_role": "Server Admin"
}
}
settings.json includes these other settings:
This script is provided completely without license, warranty, or guarantee. You are solely responsible for reviewing and understanding any software or code downloaded or run on any machine or service that you control.
Posted in: Uncategorized | Tags: obs, python
Comments are closed.