{"id":13758495,"url":"https://github.com/sharkbound/PythonTwitchBotFramework","last_synced_at":"2025-05-10T08:30:27.898Z","repository":{"id":37796235,"uuid":"134095615","full_name":"sharkbound/PythonTwitchBotFramework","owner":"sharkbound","description":"asynchronous twitchbot framework made in pure python","archived":false,"fork":false,"pushed_at":"2025-05-01T22:21:14.000Z","size":833,"stargazers_count":100,"open_issues_count":3,"forks_count":27,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-05-05T06:09:19.143Z","etag":null,"topics":["async","bot","framework","python3","sqlalchemy","twitch","twitch-api","twitch-bot"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sharkbound.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-05-19T20:24:24.000Z","updated_at":"2025-04-10T19:00:55.000Z","dependencies_parsed_at":"2024-11-16T15:32:19.962Z","dependency_job_id":"6ef077f1-6cde-4477-8b7c-3013561f4803","html_url":"https://github.com/sharkbound/PythonTwitchBotFramework","commit_stats":{"total_commits":854,"total_committers":12,"mean_commits":71.16666666666667,"dds":0.07259953161592503,"last_synced_commit":"d1808a087517610d4ff75a6deef7050958fd8f9c"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sharkbound%2FPythonTwitchBotFramework","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sharkbound%2FPythonTwitchBotFramework/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sharkbound%2FPythonTwitchBotFramework/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sharkbound%2FPythonTwitchBotFramework/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sharkbound","download_url":"https://codeload.github.com/sharkbound/PythonTwitchBotFramework/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253389409,"owners_count":21900756,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["async","bot","framework","python3","sqlalchemy","twitch","twitch-api","twitch-bot"],"created_at":"2024-08-03T13:00:31.273Z","updated_at":"2025-05-10T08:30:27.430Z","avatar_url":"https://github.com/sharkbound.png","language":"Python","readme":"# if you have any questions concerning the bot, you can contact me in my discord server: https://discord.gg/PXrKVHp OR [r/pythontwitchbot](https://www.reddit.com/r/pythontwitchbot/) on reddit\n\nif you would like to send a few dollars my way you can do so\nhere: [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\u0026hosted_button_id=9ZVUE7CR24738)\n\nthis bot is also on PYPI: https://pypi.org/project/PythonTwitchBotFramework/\n\ninstall from pip: `pip install PythonTwitchBotFramework`\n\n# PythonTwitchBotFramework\n\nfully async twitchbot framework/library compatible with python 3.6+\n\nFirst and foremost, I want to thank anyone who uses this, or even is just reading this readme,\nand to any contributors who have helped with updates/features.\n\n## Note about the wiki and readme right now:\n\nI am in the process of adding missing info to the wiki/readme,\nand also updating to show the new command argument handling added in 2.7.0+.\n(referring to the fact the command system now supporting and enforcing typehints, and not requiring *args anymore)\n\nAs well as some features i didn't put in the wiki or readme yet.\n\nIf you are any version earlier than 2.7.0, some things showcased/described on the wiki may not work for you.\n\n## How to stop the bot\n\nto stop the bot running, do any of these commands:\n\n`!shutdown` or `!stop` in the twitch chat of the channel its in, this command tries to properly shutdown all the\ntasks the bot is currently running and gives time to stop/cancel\n\nthese commands require the caller have permission to execute them\n\n# Note:\n\n### This readme only goes over basic info meant to help quickly get something working, the [GITHUB WIKI](https://github.com/sharkbound/PythonTwitchBotFramework/wiki) goes more in depth.\n\n# Index\n\n* [Quick Start](#quick-start)\n* [Overriding Events](#overriding-events)\n* [Overriding Events On Mods](#overriding-events-on-mods)\n* [Adding Commands](#adding-commands)\n* [SubCommands](#subcommands)\n* [DummyCommands](#dummycommands)\n* [Permissions](#permissions)\n    * [Using Chat Commands](#managing-permissions-using-chat-commands)\n    * [Editing The Config](#managing-permission-by-editing-the-configs)\n* [Reloading Permissions](#reloading-permissions)\n* [Command Server](#command-server)\n* [Command Console](#command-console)\n* [Database Support](#database-support)\n* [Command Whitelist](#command-whitelist)\n* [Twitch PubSub Client](#twitch-pubsub-client)\n\n# Basic info\n\nThis is a fully async twitch bot framework complete with:\n\n* builtin command system using decorators\n* overridable events (message received, whisper received, ect)\n* full permission system that is individual for each channel\n* message timers\n* quotes\n* custom commands\n* builtin economy\n\nthere is also mod system builtin to the bot, there is a collection of pre-made mods\nhere: [MODS](https://github.com/sharkbound/twitch_bot_mods)\n\n# Quick Start\n\nfor a reference for builtin command look at the\nwiki [HERE](https://github.com/sharkbound/PythonTwitchBotFramework/wiki/Builtin_Command_Reference)\n\nthe minimum code to get the bot running is this:\n\n```python\nfrom twitchbot import BaseBot\n\nif __name__ == '__main__':\n    BaseBot().run()\n```\n\nthis will start the bot.\n\nif you have a folder with your own custom commands you can load the .py files in it with:\n\n```python\nfrom twitchbot import BaseBot\n\nif __name__ == '__main__':\n    BaseBot().run()\n```\n\n# Overriding Events\n\nthe bots events are overridable via the following 2 ways:\n\n## Using decorators:\n\n```python\nfrom twitchbot import event_handler, Event, Message\n\n\n@event_handler(Event.on_privmsg_received)\nasync def on_privmsg_received(msg: Message):\n    print(f'{msg.author} sent message {msg.content} to channel {msg.channel_name}')\n```\n\n## Subclassing BaseBot\n\n```python\nfrom twitchbot import BaseBot, Message\n\n\nclass MyCustomTwitchBot(BaseBot):\n    async def on_privmsg_received(self, msg: Message):\n        print(f'{msg.author} sent message {msg.content} to channel {msg.channel_name}')\n```\n\nthen you would use MyCustomTwitchBot instead of BaseBot:\n\n```python\nMyCustomTwitchBot().run()\n```\n\n## Overriding Events On Mods\n\nVisit [***the mods wiki page***](https://github.com/sharkbound/PythonTwitchBotFramework/wiki/Mods#index)\non this repo's wiki to view how to do it via Mods\n\n* all overridable events are:\n\n#### when using the decorator event override way, `self` is not included, ex: `(self, msg: Message)` becomes: `(msg: Message)`\n\n```python\nfrom twitchbot import Event\n\nEvent.on_connected: (self)\nEvent.on_permission_check: (self, msg\n                            : Message, cmd: Command) -\u003e Optional[\n    bool]  # return False to deny permission to execute the cmd, Return None to ignore and continue\nEvent.on_after_command_execute: (self, msg: Message, cmd: Command)\nEvent.on_before_command_execute: (self, msg: Message, cmd: Command) -\u003e bool  # return False to cancel command\nEvent.on_bits_donated: (self, msg: Message, bits: int)\nEvent.on_channel_raided: (self, channel: Channel, raider: str, viewer_count: int)\nEvent.on_channel_joined: (self, channel: Channel)\nEvent.on_channel_subscription: (self, subscriber: str, channel: Channel, msg: Message)\nEvent.on_privmsg_received: (self, msg: Message)\nEvent.on_privmsg_sent: (self, msg: str, channel: str, sender: str)\nEvent.on_whisper_received: (self, msg: Message)\nEvent.on_whisper_sent: (self, msg: str, receiver: str, sender: str)\nEvent.on_raw_message: (self, msg: Message)\nEvent.on_user_join: (self, user: str, channel: Channel)\nEvent.on_user_part: (self, user: str, channel: Channel)\nEvent.on_mod_reloaded: (self, mod: Mod)\nEvent.on_channel_points_redemption: (self, msg: Message, reward: str)\nEvent.on_bot_timed_out_from_channel: (self, msg: Message, channel: Channel, seconds: int)\nEvent.on_bot_banned_from_channel: (self, msg: Message, channel: Channel)\nEvent.on_poll_started: (self, channel: Channel, poll: PollData)\nEvent.on_poll_ended: (self, channel: Channel, poll: PollData)\nEvent.on_pubsub_received: (self, raw: 'PubSubData')\nEvent.on_pubsub_custom_channel_point_reward: (self, raw: 'PubSubData', data: 'PubSubPointRedemption')\nEvent.on_pubsub_bits: (self, raw: 'PubSubData', data: 'PubSubBits')\nEvent.on_pubsub_moderation_action: (self, raw: 'PubSubData', data: 'PubSubModerationAction')\nEvent.on_pubsub_subscription: (self, raw: 'PubSubData', data: 'PubSubSubscription')\nEvent.on_pubsub_twitch_poll_update: (self, raw: 'PubSubData', poll: 'PubSubPollData')\nEvent.on_pubsub_user_follow: (self, raw: 'PubSubData', data: 'PubSubFollow')\nEvent.on_bot_shutdown: (self)\nEvent.on_after_database_init(self)  # used for triggering database operations after the bot starts\n```\n\nif this is the first time running the bot it will generate a folder named `configs`.\n\ninside is `config.json` which you put the authentication into\n\nas the bot is used it will also generate channel permission files in the `configs` folder\n\n# Adding Commands\n\nto register your own commands use the Command decorator:\n\n* Using decorators\n\n```python\nfrom twitchbot import Command, Message\n\n\n@Command('COMMAND_NAME')\nasync def cmd_function(msg: Message):\n    await msg.reply('i was called!')\n```\n\n* you can also limit the commands to be whisper or channel chat only\n  (default is channel chat only)\n\n```python\nfrom twitchbot import Command, CommandContext, Message\n\n\n# other options are CommandContext.BOTH and CommandContext.WHISPER\n@Command('COMMAND_NAME', context=CommandContext.CHANNEL)  # this is the default command context\nasync def cmd_function(msg: Message):\n    await msg.reply('i was called!')\n```\n\n* you can also specify if a permission is required to be able to call the command (if no permission is specified anyone\n  can call the command):\n\n```python\nfrom twitchbot import Command, Message\n\n\n@Command('COMMAND_NAME', permission='PERMISSION_NAME')\nasync def cmd_function(msg: Message):\n    await msg.reply('i was called!')\n```\n\n* you can also specify a help/syntax for the command for the help chat command to give into on it:\n\n```python\nfrom twitchbot import Command, Message\n\n\n@Command('COMMAND_NAME', help='this command does a very important thing!', syntax='\u003cname\u003e')\nasync def cmd_function(msg: Message):\n    await msg.reply('i was called!')\n```\n\nso when you do `!help COMMAND_NAME`\n\nit will this in chat:\n\n```\nhelp for \"!command_name\", \nsyntax: \"\u003cname\u003e\", \nhelp: \"this command does a very important thing!\"\n```\n\n* you can add aliases for a command (other command names that refer to the same command):\n\n```python\nfrom twitchbot import Command, Message\n\n\n@Command('COMMAND_NAME',\n         help='this command does a very important thing!',\n         syntax='\u003cname\u003e',\n         aliases=['COMMAND_NAME_2', 'COMMAND_NAME_3'])\nasync def cmd_function(msg: Message):\n    await msg.reply('i was called!')\n```\n\n`COMMAND_NAME_2` and `COMMAND_NAME_2` both refer to `COMMAND_NAME` and all three execute the same command\n\n# SubCommands\n\nthe SubCommand class makes it easier to implement different actions based on a parameters passed to a command.\n\nits the same as normal command except thats its not a global command\n\nexample: `!say` could be its own command, then it could have the sub-commands `!say myname` or `!say motd`.\n\nyou can implements this using something like this:\n\n```python\nfrom twitchbot import Command, Message\n\n\n@Command('say')\nasync def cmd_say(msg: Message, *args):\n    # args is empty\n    if not args:\n        await msg.reply(\"you didn't give me any arguments :(\")\n        return\n\n    arg = args[0].lower()\n    if arg == 'myname':\n        await msg.reply(f'hello {msg.mention}!')\n\n    elif arg == 'motd':\n        await msg.reply('the message of the day is: python is awesome')\n\n    else:\n        await msg.reply(' '.join(args))\n\n\n```\n\nthat works, but it can be done in a nicer way using the `SubCommand` class:\n\n```python\nfrom twitchbot import Command, SubCommand, Message\n\n\n@Command('say')\nasync def cmd_say(msg: Message, *args):\n    await msg.reply(' '.join(args))\n\n\n# we pass the parent command as the first parameter   \n@SubCommand(cmd_say, 'myname')\nasync def cmd_say_myname(msg: Message):\n    await msg.reply(f'hello {msg.mention}!')\n\n\n@SubCommand(cmd_say, 'motd')\nasync def cmd_say_motd(msg: Message):\n    await msg.reply('the message of the day is: python is awesome')\n```\n\nboth ways do the same thing, what you proffer to use is up to you, but it does make it easier to manage for larger\ncommands to use SubCommand class\n\n# DummyCommands\n\nthis class is basically a command that does nothing when executed, its mainly use is to be used as base command for\nsub-command-only commands\n\nit has all the same options as a regular Command\n\nwhen a dummy command is executed it looks for sub-commands with a matching name as the first argument passed to it\n\nif no command is found then it will say in chat the available sub-commands\n\nbut if a command is found it executes that command\n\nsay you want a command to greet someone, but you always want to pass the language, you can do this:\n\n```python\nfrom twitchbot import DummyCommand, SubCommand, Message\n\n# cmd_greet does nothing itself when called\ncmd_greet = DummyCommand('greet')\n\n\n@SubCommand(cmd_greet, 'english')\nasync def cmd_greet_english(msg: Message):\n    await msg.reply(f'hello {msg.mention}!')\n\n\n@SubCommand(cmd_greet, 'spanish')\nasync def cmd_greet_spanish(msg: Message):\n    await msg.reply(f'hola {msg.mention}!')\n```\n\ndoing just `!greet` will make the bot say:\n\n```text\ncommand options: {english, spanish}\n```\n\ndoing `!greet english` will make the bot say this:\n\n```text\nhello @johndoe!\n```\n\ndoing `!greet spanish` will make the bot say this:\n\n```text\nhola @johndoe!\n```\n\n# Config\n\nthe default config values are:\n\n```json\n{\n  \"nick\": \"nick\",\n  \"oauth\": \"oauth:\",\n  \"client_id\": \"CLIENT_ID\",\n  \"prefix\": \"!\",\n  \"default_balance\": 200,\n  \"loyalty_interval\": 60,\n  \"loyalty_amount\": 2,\n  \"owner\": \"BOT_OWNER_NAME\",\n  \"channels\": [\n    \"channel\"\n  ],\n  \"mods_folder\": \"mods\",\n  \"commands_folder\": \"commands\",\n  \"command_server_enabled\": true,\n  \"command_server_port\": 1337,\n  \"command_server_host\": \"localhost\",\n  \"disable_whispers\": false,\n  \"use_command_whitelist\": false,\n  \"send_message_on_command_whitelist_deny\": true,\n  \"command_whitelist\": [\n    \"help\",\n    \"commands\",\n    \"reloadcmdwhitelist\",\n    \"reloadmod\",\n    \"reloadperms\",\n    \"disablemod\",\n    \"enablemod\",\n    \"disablecmdglobal\",\n    \"disablecmd\",\n    \"enablecmdglobal\",\n    \"enablecmd\",\n    \"addcmd\",\n    \"delcmd\",\n    \"updatecmd\",\n    \"cmd\"\n  ]\n}\n```\n\n`oauth` is the twitch oauth used to login\n\n`client_id` is the client_id used to get info like channel title, ect ( this is not required but twitch API info will\nnot be available without it )\n\n`nick` is the twitch accounts nickname\n\n`prefix` is the command prefix the bot will use for commands that dont use custom prefixes\n\n`default_balance `is the default balance for new users that dont already have a economy balance\n\n`owner` is the bot's owner\n\n`channels` in the twitch channels the bot will join\n\n`loyalty_interval` the interval for which the viewers will given currency for watching the stream, gives amount\nspecified by `loyalty_amount`\n\n`loyalty_amount` the amount of currency to give viewers every `loyalty_interval`\n\n`command_server_enabled` specifies if the command server should be enabled (see [Command Server](#command-server) for\nmore info)\n\n`command_server_port` the port for the command server\n\n`command_server_host` the host name (address) for the command server\n\n`disable_whispers` is this value is set to `true` all whispers will be converted to regular channel messages\n\n`use_command_whitelist` enabled or disables the command whitelist (see [Command Whitelist](#command-whitelist))\n\n`send_message_on_command_whitelist_deny` should the bot tell users when you try to use a non-whitelisted command?\n\n`command_whitelist` json array of commands whitelisted without their prefix (only applicable\nif [Command Whitelist](#command-whitelist) is enabled)\n\n# Permissions\n\nthe bot comes default with permission support\n\nthere are two ways to manage permissions,\n\n1. using chat commands\n2. editing JSON permission files\n\n## managing permissions using chat commands\n\nto add a permission group: `!addgroup \u003cgroup\u003e`, ex: `!addgroup donators`\n\nto add a member to a group: `!addmember \u003cgroup\u003e \u003cuser\u003e`, ex:\n`!addmember donators johndoe`\n\nto add a permission to a group: `!addperm \u003cgroup\u003e \u003cpermission\u003e`, ex:\n`!addperm donators slap`\n\nto remove a group: `!delgroup \u003cgroup\u003e`, ex: `!delgroup donators`\n\nto remove a member from a group: `!delmember \u003cgroup\u003e \u003cmember\u003e`, ex:\n`!delmember donators johndoe`\n\nto remove a permission from a group: `!delperm \u003cgroup\u003e \u003cpermission\u003e`, ex:\n`!delperm donators slap`\n\n### tip: revoking permission for a group (aka negating permissions)\n\nto revoke a permission for a group, add the same permission but with a - in front of it\n\nex: you can to prevent group B from using permission `feed` from group A.\n\nSimply add its negated version to group B: `-feed`, this PREVENTS group B from having the permission `feed` from group A\n\n## managing permission by editing the configs\n\nfind the `configs` folder the bot generated (will be in same directory as the script that run the bot)\n\ninside you will find `config.json` with the bot config values required for authentication with twitch and such\n\nif the bot has joined any channels then you will see file names that look like `CHANNELNAME_perms.json`\n\nfor this example i will use a `johndoe`\n\nso if you open `johndoe_perms.json` you will see this if you have not changed anything in it:\n\n```json\n{\n  \"admin\": {\n    \"name\": \"admin\",\n    \"permissions\": [\n      \"*\"\n    ],\n    \"members\": [\n      \"johndoe\"\n    ]\n  }\n}\n```\n\n`name` is the name of the permission group\n\n`permissions` is the list of permissions the group has\n(\"*\" is the \"god\" permission, granting access to all bot commands)\n\n`members` is the members of the group\n\nto add more permission groups by editing the config you can just copy/paste the default one\n(be sure to remove the \"god\" permission if you dont them having access to all bot commands)\n\nso after copy/pasting the default group it will look like this\n(dont forget to separate the groups using `,`):\n\n```json\n{\n  \"admin\": {\n    \"name\": \"admin\",\n    \"permissions\": [\n      \"*\"\n    ],\n    \"members\": [\n      \"johndoe\"\n    ]\n  },\n  \"donator\": {\n    \"name\": \"donator\",\n    \"permissions\": [\n      \"slap\"\n    ],\n    \"members\": [\n      \"johndoe\"\n    ]\n  }\n}\n```\n\n# Reloading Permissions\n\nif the bot is running be sure to do `!reloadperms` to load the changes to the permission file\n\n# Command Server\n\nThe command server is a small Socket Server the bot host that lets the Command Console be able to make the bot send\nmessages given to it through a console. (see [Command Console](#command-console))\n\nThe server can be enabled or disabled through the config (see [Config](#config)), the server's port and host are\nspecified by the config file\n\n# Command Console\n\nIf the [Command Server](#command-server) is disabled in the [config](#config) the Command Console cannot be used\n\nThe Command Console is used to make the bot send chat messages and commands\n\nTo launch the Command Console make sure the bot is running, and the [Command Server](#command-server) is enabled in\nthe [Config](#config),\n\nafter verifying these are done, simply do `python command_console.py` to open the console, upon opening it you will be\nprompted to select a twitch channel that the bot is currently connected to.\n\nafter choose the channel the prompt changes to `(CHANNEL_HERE):` and you are now able to send chat messages / commands\nto the choosen channel by typing your message and pressing enter\n\n# Database Support\n\nto enabled database support\n\n* open `configs/database_config.json` (if its missing run the bot and close it, this should\n  generate `database_config.json`)\n* set `enabled` to `true`\n* fill in `address`, `port`, `username`, `password`, and `database` (you will need to edit `driver`/`database_format` if\n  you use something other than mysql or sqlite)\n* install the mysql library (if needed) FOR MYSQL INSTALL: `pip install --upgrade --user mysql-connector-python`, or any\n  other database supported by sqlalchemy, see the\n  sqlalchemy [engines](https://docs.sqlalchemy.org/en/13/core/engines.html). like for example POSTGRES:\n  `pip install --upgrade psycopg2`\n* rerun the bot\n\n# Command Whitelist\n\nCommand whitelist is a optional feature that only allows certain commands to be used (specified in the config)\n\nit is disabled by default, but can be enabled by setting `use_command_whitelist` to `true` in `configs/config.json`\n\nCommand Whitelist limits what commands are enabled / usable on the bot\n\nif a command that is not whitelisted is ran, it will tell the command caller that it is not whitelisted\nif `send_message_on_command_whitelist_deny` is set to `true`, otherwise it will silently NOT RUN the command\n\nwhitelisted commands can be edited with the `command_whitelist` json-array in `configs/config.json`\n\nto edit the command whitelist, you can add or remove elements from the `command_whitelist` json-array, do not include\nthe command's prefix, AKA `!command` becomes `command` in `command_whitelist`\n\n### To reload the whitelist, restart the bot, or do `!reloadcmdwhitelist` in your the twitch chat (requires having `manage_commands` permission)\n\n# Twitch PubSub Client\n\n## what is pubsub?\n\npubsub is the way twitch sends certain events to subscribers to the topic it originates from\n\nall topics are listed under the `PubSubTopics`\nenum [found here](https://github.com/sharkbound/PythonTwitchBotFramework/blob/master/twitchbot/pubsub/topics.py)\n\n## Requirements\n\n### Step 1: creating a developer application\n\nto create a twitch developer application [generate one here](https://dev.twitch.tv/console/apps), this requires the\naccount have two-factor enabled\n\n1. visit [https://dev.twitch.tv/console/apps](https://dev.twitch.tv/console/apps)\n1. click `+ Register new application`\n1. for redirect uri set it as `https://twitchapps.com/tmi/`, then click `add`\n1. for the purpose of the application, select `Chat Bot`\n1. for name, you can do anything, as long as it does not contain `twitch` in it\n1. finally, create the application\n\n## Step 2: generating a new irc oauth access token with the new client_id\n\nthis step is needed because twitch requires that oauth tokens used in API calls be generated the client_id sent in the\napi request\n\nafter you create the application click it and copy its client id, then paste it into the bot's config.json file located\nat `configs/config.json` for the field `client_id`, like so:\n\n```json\n{\n  \"client_id\": \"CLIENT_ID_HERE\"\n}\n```\n\nnow you need to generate a oauth for the bot's primary irc oauth that matches the client_id, there is a utility i\nmade [HERE](https://github.com/sharkbound/PythonTwitchBotFramework/blob/master/util/token_utils.py) to help with token\nauthorization URL generation\n\nusing that utility, add this code to the bottom of the util script .py file, you would generate the URL like so:\n\n```python\nprint(generate_irc_oauth('CLIENT_ID_HERE', 'REDIRECT_URI_HERE'))\n```\n\nOR just replace the values in this auth url:\n\n```\nhttps://id.twitch.tv/oauth2/authorize?response_type=token\u0026client_id=\u003cCLIENT_ID\u003e\u0026redirect_uri=\u003cREDIRECT_URI\u003e\u0026scope=chat:read+chat:edit+channel:moderate+whispers:read+whispers:edit+channel_editor\n```\n\nopen a browser window that is logged into your bot account and visit the values-replaced authorization URL\n\nafter you authorize it, copy the oauth access token and paste it into the bot's config for the value of `oauth`, ex:\n\n```json\n{\n  \"oauth\": \"oauth:\u003cOAUTH_HERE\u003e\"\n}\n```\n\nthis ensures that API calls still work.\n\n## Step 3: creating the pubsub oauth access token\n\nthis oauth token is responsible for actually allowing the bot to access oauth topics on a specific channel\n\nthe list of scopes needed for different topics can be found [HERE](https://dev.twitch.tv/docs/pubsub#topics), each topic\nhas its own scope it needs, all the scope permissions as strings for my util script can be found here:\n[https://github.com/sharkbound/PythonTwitchBotFramework/blob/master/util/token_utils.py#L4](https://github.com/sharkbound/PythonTwitchBotFramework/blob/master/util/token_utils.py#L4)\n\n(if you dont want to use the util script just use this url and add the needed\ninfo: `https://id.twitch.tv/oauth2/authorize?response_type=token\u0026client_id={client_id}\u0026redirect_uri={redirect}\u0026scope={scopes}`\n, scopes are separated with a + in the url)\n\n(the following will use my util script, this also assumes you have downloaded/copied the token utility script as well)\n\nto create the pubsub token, first decide on WHAT topics it needs to listen to, i will use `PubSubTopics.channel_points`\nwith this example\n\nusing the utility script, you can call `generate_auth_url` to generate the authorization URL for you\n\n```python\nprint(generate_auth_url('CLIENT_ID_HERE', 'REDIRECT_URI_HERE', Scopes.PUBSUB_CHANNEL_POINTS))\n```\n\n### Required OAuth Scopes for PubSub topics\n\n```\n|____________________________|______________________________|\n|            TOPIC           |      REQUIRED OAUTH SCOPE    |\n|____________________________|______________________________|\nfollowers                     -\u003e channel_editor\npolls                         -\u003e channel_editor\nbits                          -\u003e bits:read\nbits badge notification       -\u003e bits:read\nchannel points                -\u003e channel:read:redemptions\ncommunity channel points      -\u003e (not sure, seems to be included in the irc oauth)\nchannel subscriptions         -\u003e channel_subscriptions\nchat (aka moderation actions) -\u003e channel:moderate\nwhispers                      -\u003e whispers:read\nchannel subscriptions         -\u003e channel_subscriptions\n```\n\nthe `[PubSubTopics.channel_points]` is the list of scopes to add to the authorization request url\n\nafter the URL is printed, copy it and visit/send the url to owner of the channel that you want pubsub access to\n\nin the case of it being your own channel its much more simple, since you just need to visit it on your main account and\ncopy the oauth access code\n\n## Using the pubsub oauth\n\n1. go to the bot's folder/directory on the computer running\n1. look for the `mods` folder\n1. create `pubsub_subscribe.py` in the `mods` directory\n1. paste the following template in it:\n\n```python\nfrom twitchbot import PubSubTopics, Mod, get_pubsub\n\n\nclass PubSubSubscriberMod(Mod):\n    async def on_connected(self):\n        await get_pubsub().listen_to_channel('CHANNEL_HERE', [PubSubTopics.channel_points],\n                                             access_token='PUBSUB_OAUTH_HERE')\n\n    # only needed in most cases for verifying a connection\n    # this can be removed once verified\n    async def on_pubsub_received(self, raw: 'PubSubData'):\n        # this should print any errors received from twitch\n        print(raw.raw_data)\n```\n\nafter a successful pubsub connection is established, you can override the appropriate event (some pubsub topics dont\nhave a event yet, so use on_pubsub_received for those)\n\nfollowing the above example we will override the `Event.on_pubsub_custom_channel_point_reward` event\n\n```python\nfrom twitchbot import PubSubTopics, Mod, get_pubsub\n\n\nclass PubSubSubscriberMod(Mod):\n    async def on_connected(self):\n        await get_pubsub().listen_to_channel('CHANNEL_HERE', [PubSubTopics.channel_points],\n                                             access_token='PUBSUB_OAUTH_HERE')\n\n    # only needed in most cases for verifying a connection\n    # this can be removed once verified\n    async def on_pubsub_received(self, raw: 'PubSubData'):\n        # this should print any errors received from twitch\n        print(raw.raw_data)\n\n    # twitch only sends non-default channel point rewards over pubsub \n    async def on_pubsub_custom_channel_point_reward(self, raw: 'PubSubData', data: 'PubSubPointRedemption'):\n        print(f'{data.user_display_name} has redeemed {data.reward_title}')\n```\n\nthat pretty much summarized how to use pubsub, if you have any more questions, or need help, do visit my discord server\nor subreddit (found at top of this readme)","funding_links":["https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\u0026hosted_button_id=9ZVUE7CR24738"],"categories":["Libraries"],"sub_categories":["Python"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsharkbound%2FPythonTwitchBotFramework","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsharkbound%2FPythonTwitchBotFramework","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsharkbound%2FPythonTwitchBotFramework/lists"}