References

TwitchBot Module

class TwitchPy.TwitchBot.Client(*, token: str, user: str, client_id: str, channel: str, chatlimit: int = None, logger=<TwitchPy.Logger.Logger object>, eventhandler=<TwitchPy.Events.Handler object>)

The central part of the TwitchPy bot.

This is responsible for creating many parts of the bot as well as running everything. Every bot should create an instance of this bot.

Keyword Arguments:
 
  • token (str) –

    The bot’s oauth token. MUST start with ‘oauth:’ .

    For example, if your oauth was 123456, then this should be ‘oauth:123456’

  • user (str) – The username of the account the bot logs in to.
  • client_id (str) – The bot’s client ID.
  • channel (str) – The channel you want the bot to connect to.
  • chatlimit (int) – The maximum number of chat messages to hold on to. See Websocket.IRC
  • logger (Logger.Logger (optional)) –

    The bot’s custom logger. If not given, TwitchPy will give you a very basic logger (see Logger.Logger preset=’default’).

    If you don’t want any logger, create an instance of Logger.Logger without filling in any fields.

    Example: bot = TwitchBot.Client(logger=Logger))

  • eventhandler (Events.Handler (optional)) – An event handler if you wanted to set one up. If you do, make sure you create a class that inherits from Events.Handler . For more info see Events.Handler
Variables:
  • events (Event.Handler) – See eventhandler in keyword arguments
  • logger (Logger.Logger) – See keyword arguments.
  • command_cogs ((Command.Cog)) – A set of all the command cogs you added.
  • API (API.Helix) – The API handler.
  • IRC (Websocket.IRC) – The IRC handler.
  • tasks (list) – A list of functions to execute concurrently with the bot. See TwitchBot.Client.run() for more info.
Raises:

TypeError – Raised if kwargs are not the correct data type.

add_cogs(cogs: list)

Adds commands to the bot.

Commands follow a cog system that lets you categorize groups of commands, mostly for organization.

Parameters:cog (Commands.Cog or [Commands.Cog]) – The cogs to add to the bot. To see how to make a cog, see Commands.Cog .
Raises:TypeError – Raised if parameters are not the correct data type.
change_channel(channel: str)

Moves the bot from one twitch channel to another.

Parameters:channel (str) – The channel to connect to.
Raises:TypeError – Raised if parameters are not the correct data type.
get_API() → TwitchPy.API.Helix
get_IRC() → TwitchPy.Websocket.IRC
get_Logger() → TwitchPy.Logger.Logger
kill()

Gracefully shuts down the bot and it’s IRC connections.

run(funcs: list = [])

Starts the main functions of the bot.

After initializing everything, calling this will start the bots listener to start listening to twitch chat and determing which commands (if any) to execute. This will also start running any async functions you want to run concurrently with the other functions of the bot.

Parameters:funcs (func or [func]) –

A list of async functions that you want to run alongside (concurrently) with the bot’s other functions. Some common uses for this is if you wanted the bot do something every x seconds.

These async functions must follow these rules:

  • Must have at least one call to asyncio.sleep(x) where x is an amount of time in seconds. This is what allows the concurrency. If you don’t have this, the bot will get hung up on one of the tasks and not function properly.
  • Must NOT take any arguments.
Raises:TypeError – Raised if paramaters are not the correct data type.

Commands Module

class TwitchPy.Commands.Cog(*, prefix: str, logger=None, eventhandler=None)

A structure to hold commands defined by you.

Cogs hold commands you created using the decorator @Commands.create() (see Commands.create() for more details on what this is and how to use it), and determines which commands to execute based on permissions and arguments.

Keyword Arguments:
 
  • prefix (str) – The prefix for these commands so the bot knows that the following message is meant for it. For example, most bots use ‘!’ as their prefix.
  • logger (Logger.Logger (optional)) – TwitchPy’s logger. If not given, TwitchPy will give whatever instance of Logger.Logger that TwitchBot.Client has when TwitchBot.Client.add_cog() is called.
  • eventhandler (Events.Handler (optional)) – The eventhandler. If not given, TwitchPy will give whatever instance of Events.Handler that TwitchBot.Client has when TwitchBot.Client.add_cog() is called.
Variables:
  • prefix (str) – See keyword arguments.
  • all_commands (dict) – A dictionary containing all of your commands whose keys are (‘commandname’, argcount) and whose values are the Commands.Command objects. What’s argcount? see Commands.create() for more info.
  • logger (Logger.Logger) – See keyword arguments
  • events (Events.Handler) – See keyword arguments
Raises:

TypeError – Raised if prefix, logger, and eventhandler are not the correct data types.

Note

For the most part, you won’t need to use these attributes in any meaningful way because TwitchPy should do all the work of selecting the command for you. But they’re here if you do want to use them for something.

Note

You should not be creating an instance of Commands.Cog, instead you should be creating your own classes that inherit this class. Make sure to call super().__init__()

Examples

>>> from TwitchPy import TwitchBot, Commands
>>>
>>> class MyClass(Commands.Cog):
>>>     def __init__(self, IRC):
>>>         super().__init__(prefix='%')
>>>         self.IRC = IRC
>>>
>>>     @Commands.create(name='ping')
>>>     async def mycommand():
>>>         self.IRC.send('pong')
>>>
>>> mybot = TwitchBot.Client(yourBotLoginInfoHere)
>>> mycog = MyClass(mybot.get_IRC())
>>> mybot.add_cog(mycog)
>>> mybot.run()

This will create a bot with prefix ‘%’ and one command named ‘ping’ that sends ‘pong’ in chat.

>>> %ping
pong
class TwitchPy.Commands.Command(func, names: [<class 'str'>], permission: str, whitelist: [<class 'str'>])

Just a struct to contain basic info on the command created.

One of these is instantiated for every command created using the decorator Commands.create()

Parameters:
  • func (function) – The function that the command will execute when it’s called.
  • names ([str]) – All the names the command will execute by.
  • permission ({'notest', 'everyone', 'subscriber', 'moderator', 'broadcaster'}) – Who is allowed to use this command based on their affiliation with the channel.
  • whitelist ([str]) – Who is allowed to use this command based on username. If used alongside permission, permissions will take precedence over whitelist.

Note

For more information on what these mean, see Commands.create()

Variables:parameters (See) –

Note

You shouldn’t have to make an instance of this class. But it might be useful for you to know what attributes this Class has if you plan on making your own command parser.

TwitchPy.Commands.create(*, name: str = [], permission: str = 'notset', whitelist: str = [])

A decorator function used to create new commands.

Requirements for creating your own command:

  1. MUST be used in a class that inherits from Commands.Cog
  2. MUST use the @ decorator syntax: @Commands.create()
  3. MUST be an async function
  4. MUST take one parameter: chat
Keyword Arguments:
 
  • name (str or [str] (optional)) – The name(s) of the command. AKA: what the viewer will type after the prefix to execute the command. If not given, the command name will be the name of the function.
  • permission ({'notset', 'everyone', 'subscriber', 'moderator', 'broadcaster'} (optional)) – Based on their affiliation to the channel, which users are allowed to use this command. Specifying any permission level implies that users with higher permission levels will be able to use the command. For example, permission=’moderator’ implies that both channel moderators and broadcasters can use it.
  • whitelist (str or [str] (optional)) – Which viewers can use this command by name. If specified along with permission, permission will take precedence over whitelist.
Raises:
  • TypeError – Raised if kwargs are not the data types they should be.
  • ValueError – Raised if the kwarg, permission, is not the correct value.

Examples

For all of these examples, assume they’re part of a class defined as such:

>>> from TwitchPy import Commands
>>> class MyClass(Commands.Cog):
>>>     def __init__(self, IRC):
>>>         super().__init__(syntax='!'')
>>>         self.IRC = IRC  # received from TwitchBot.Client().get_IRC()
>>> @Command.create()
>>> async def ping(self, chat):
>>>     self.IRC.send('pong')

The simplest example of how to create a command. This well execute whenever a viewer types in chat ‘!ping’ and the bot will respond with ‘pong’ in chat. Because name is not defined, the command name defaults to the function name: ‘ping’. Because argcount is not defined, this command will execute no matter how many arguments are sent. So ‘!ping lorem ipsum’ will still work. And because permission and whitelist are not defined, there’s no restrictions on who can use this command.

>>> @Command.create(name=['hello', 'hi', 'howdy'])
>>> async def sayhello(self, chat):
>>>     self.IRC.send('HeyGuys')

This command says in chat ‘HeyGuys’ whenever a viewer says ‘!hello’ or ‘!hi’ or ‘!howdy’. Because name is defined, the command name won’t be set to the function name: sayhello. Because aliases is defined with two strings, this command can be executed using any of the 3 names.

>>> @Command.create(name=['hello', 'hi', 'howdy'])
>>> async def advancedhello(self, chat, arg1, arg2, arg3):
>>>     self.IRC.send('VoHiYo')

This command says in chat ‘VoHiYo’ whenever a viewer says ‘!hello’ followed by three words (arg1, arg2, arg3) So ‘!hello all my friends’ or ‘!hello to everyone here’ or ‘!hello a b c’ would all work because there are three words (args) after the command nane. Note that we now have two commands with the name ‘!hello’. This is allowed because they work on two different argcounts. The function advancedhello is called only if there is three args and the function sayhello will get called whenever there’s no args.

>>> @Command.create(name=['hello', 'hi', 'howdy'])
>>> async def mediumhello(self, chat, arg1, *args):
>>>     self.IRC.send('wassup')

Because of *args, this command will execute if there’s 1 or more args. There needs to be at least 1 arg because of arg1 any extra args will be captured by *args as a list. TwitchPy will prioritize commands with more args, so TwitchPy will try to execute advancedhello before mediumhello. So if there’s 3 args, advancedhello will be called even though mediumhello can take any number of args > 1. If there’s 4 args, mediumhello is called. If there’s 2 args, mediumhello is called. If there’s 1 arg, mediumhello is called.

NOTE: If two commands have the same name and argcounts (*args does not count toward argcount), then only one will be executed.

>>> @Command.create(permisison='moderator')
>>> async def permissionhello(self, chat):
>>>     self.IRC.send('hello mod or broadcaster')

This command will only execute if a moderator or a broadcaster says ‘!mod’.

>>> @Command.create(whitelist=['someviewer'])
>>> async def whitelisthello(self, chat):
>>>     self.IRC.send('hello someviewer')

This command will only execute if the viewer who sent the message is named ‘someviewer’

>>> @Command.create(permission='moderator', whitelist=['someviewer'])
>>> async def reallyspecifichello(self, chat):
>>>     self.IRC.send('hello mod, broadcaster, or someviewer')

This command will execute if any moderator or broadcaster sends the message as specified by permission. Additionally, if any viewer named ‘someviewer’, regardless of if they’re are a mod or a broadcaster or not, will also be able to execute the command.

Events Module

class TwitchPy.Events.Handler

Holds all the events the bot will call.

Inheriting this class allows you to overwrite its functions so you can “catch” these events.

Variables:
  • logger (Logger) – Logger object.
  • API (API.Helix) – An instance of API.Helix that allows you to access twitch endpoints.
  • IRC (Websocket.IRC) – An instance of Websocket.IRC that allows you to interact with twitch chat.

Examples

>>> from TwitchPy import TwitchBot, Events
>>>
>>> class MyClass(Events.Handler):
>>>     def __init__(self):
>>>     super().__init__()
>>>
>>>     def on_ready(self):
>>>         print('the bot is ready')
>>>
>>> bot = TwitchBot.Client(**login_info, eventhandler=MyClass())
on_bad_cmd(chat)

Called whenever the bot fails to find a command to execute. AKA: when the viewer uses the prefix but then can’t find the command the viewer is trying to use

Parameters:chat (ChatInfo.Chat) – The chat object containing basic info on the message that was sent.
on_cmd(chat)

Called after a command executes successfully.

Parameters:chat (ChatInfo.Chat) – The chat object containing basic info on the message that was sent.
on_connect()

Called right after the bot connects to a twitch channel.

on_death()

Called when the bot dies regardless of how it happens. Executes before connections are closed, allowing for the bot to send messages to chat

on_expected_death()

Called when the bot dies as a part of normal function. AKA: the user uses the kill command. Executes before on_death. Executes before connections are closed, allowing for the bot to send messages to chat.

on_log(log_type: str, record)

Called whenever the bot attempts to log something.

Parameters:
on_msg(chat)

Called whenever a viewer sends a message in twitch chat. Executes before any command can execute

Parameters:chat (ChatInfo.Chat) – The chat object containing basic info on the message that was sent.
on_no_cmd(chat)

Called whenever a viewer sends a message in chat that has nothing to do with a command cog. AKA: when the viewer doesn’t use that cog’s prefix.

Parameters:chat (ChatInfo.Chat) – The chat object containing basic info on the message that was sent.
on_ready()

Called at the end of __init__ in TwitchBot.Client

on_run()

Called at the beginning of when TwitchBot.Client.run() is called. Executes before the bot connects to chat or begins any of its loops.

on_unexpected_death(err, exc_info)

Called when the bot dies unexpectedly. AKA: when an error occurs. Executes before on_death. Executes before connections are closed, allowing for the bot to send messages to chat.

Parameters:
  • err (Exception) – The exception that caused the bot to die unexpectedly.
  • exc_info (sys.exc_info()) – More info on the exception that caused the bot to die. Acquired from sys.exc_info()

Logger Module

class TwitchPy.Logger.Logger(*, preset: str = '', chatfmt: str = '%(user.name)s: %(msg)s')

Semi-Custom Logger to log things as they happen.

Uses logging library’s logger, but with some extra features added on top. If you want to utilize this feature, you should make an instance of this class, configure it to how you like it, and then pass it into TwitchBot.Client like TwitchBot.Client(logger=MyLogger).

Features:

  • chat formatting to change how you want your twich chat messages to look in the log
  • custom filters for both console and file loggers to filter out what messages you do and do not want to see for both individually
  • presets (‘default’, ‘recommended’)
  • lets you create basic loggers so you don’t have to import logging
  • supports creating your own logger via logging and using it in this
Keyword Arguments:
 
  • preset ({'default', 'recommended'} (optional)) –

    If you’re too lazy to customize your logger or just don’t have many strong feelings about what you want, we offer two presets that you can use.

    ’default’ is a very basic, console-only logger that only shows basic functions the bot is doing.

    ’recommended’ is what we built the logger with in mind. It prints to console all the init messages and above, but logs to a file ‘TwitchBot.log’ only basic functions and above.

  • chatfmt (str (optional)) – The % string format to dictate how the logger should log chat messages. The variables should be in the scope of ChatInfo.Chat . So if you wanted to access the username of who sent the message you would use ‘%(user.name)s’. If not given, chatfmt will default to ‘%(user.name)s: %(msg)s’.

Note

If you don’t want the bot to have a logger, you must still create an instance of this class. When you do, don’t define any of the paramters and the bot won’t log anything.

Variables:
  • console (logging.Logger) – An instance of logging.Logger used specifically to log to the console.
  • file (logging.Logger) – An instance of logging.Logger used specifically to log to files.
  • filter (dict) – A filter so you can decide what the console and file loggers can and can’t log. Note: This is not the filter from the logging library.
Raises:
  • TypeError – Raised if kwargs are not the correct data types.
  • ValueError – Raised if the kwarg, preset, is not the correct value.

Note

We hold two instances of loggers (console and file) so you can more precisely control the behaviors of each, allowing the console logger to act differently than the file logger.

Note

While we don’t inherently support more than two loggers (one for the console and one for file), the console logger and file logger names are purely cosmetic. We make no checks to ensure that those loggers have purely consolehandlers or filehandlers. Additionally, we support you defining your own logger (via the logging module) and using the Logger.set[loggertype]() function. So you could make a logger, add a filehandler, and pass it to Logger.set_console_logger() and that would work without problem. This means that if you wanted to do things like printing to multiple files at the same time, or other things that might require more than two loggers, you might be able to find some crafty solutions at: https://docs.python.org/3/howto/logging-cookbook.html

Alternatively, if that’s too confusing or doesn’t quite allow you to do what you want to do, you can always catch the on_log event which will be called whenever the bot tries to log something. The on_log event will receive the same information that the logger would.

console_filter(filter_: [<class 'str'>])

Lets you set custom filters to decide what you do and do not want your logger to see.

For most purposes, just setting the logger’s level is good enough, but this is here to give you even finer control than that.

Note: This will only effect Logger.Logger.console

Note

NOT to be confused with logging filters: https://docs.python.org/3/library/logging.html#filter-objects

Parameters:filter

A list of all the things you do NOT want the logger to see. Each entry should be structured as so: Module-Type

A list of all bot filters:
  • ’TwitchBot-init’ : init related messages
  • ’TwitchBot-basic’ : the basic function of the module
  • ’TwitchBot-error’ : error messages
  • ’API-init’
  • ’API-basic’
  • ’API-request_get’ : exactly what the bot is sending via requests
  • ’API-request_response’ : the exact response from the twitch API endpoint
  • ’API-error’
  • ’Websocket-init’
  • ’Websocket-basic’
  • ’Websocket-incoming’ : only the incoming messages from twitch chat
  • ’Websocket-outgoing’ : only the outgoing messages from twitch chat
  • ’Websocket-send’ : exactly what the bot sends via websocket
  • ’Websocket-recv’ : what twitch IRC sends back at us
  • ’Websocket-error’
  • ’Events-init’
  • ’Commands-error’
Raises:TypeError – Raised if parameters are not the correct data type.
create_console_logger(*, fmt='[%(levelname)-8s] [%(module)-10s] [%(asctime)s] %(message)s', datefmt='%H:%M:%S', level=11)

A convenient function to create a logger without you having to import the loggin module.

Note: This will set Logger.Logger.console

Keyword Arguments:
 
Raises:

TypeError – Raised if kwargs are not the correct data type.

create_file_logger(*, filename='TwitchBot.log', filemode='a', fmt='[%(levelname)-8s] [%(module)-10s] [%(asctime)s] %(message)s', datefmt='%Y/%m/%d - %H:%M:%S', level=19)

See Logger.Logger.create_console_logger() for any missing information

Note: This will set Logger.Logger.file

Keyword Arguments:
 
  • filename (str (optional)) – The path / filename of the file to log to. If not given, will default to ‘TwitchBot.log’
  • filemode ({'w', 'a'} (optional)) – The writing mode. If not given, will default to ‘w’.
Raises:

TypeError – Raised if kwargs are not the correct data type.

file_filter(filter_: [<class 'str'>])

See Logger.Logger.console_filter() for a detailed explanation

Note: this will only effect Logger.Logger.file

log(level: int, type_: str, msg: str, exc=None)

Checks filters and logs your messages accordingly.

Makes a logging record object (https://docs.python.org/3/library/logging.html#logrecord-objects) by filling in the fields with information gathered from inspect frames (https://docs.python.org/3/library/inspect.html#the-interpreter-stack), then logs with the appropriate loggers according to the filters, and finally passes on the record to the on_log event.

Parameters:
  • level (int) – The level of the log message. See https://docs.python.org/2/library/logging.html#logging-levels-attributes for logging’s levels and Logger.Logger for TwitchPy’s levels. Alternatively, you can send your own level independent of both of.
  • type (str) – The type of log message. You can use the bot’s system of message types if you want, but we also support you setting up your own system of message types.
  • msg (str) – The message that’s going to be logged.
  • exc (sys.exc_info() (optional)) – You only need this if you’re logging an error and must be obtained from sys.exc_info()
Raises:

TypeError – Raised if parameters are not the correct data type.

set_chatfmt(chatfmt: str)

Allows you to set how IRC chat is displayed when it’s logged.

Parameters:chatfmt (str) – See Logger.Logger for more details.
Raises:TypeError – Raised if parameters are no the correct data type.
set_console_logger(logger)

An alternative way to set the console logger.

Instead of creating one using Logger.Logger.create_console_logger(), you can define your own logging logger outside of this class, and use this function to give it to the bot.

Parameters:logger (logging.Logger) – MUST be a logger created by the logging module.
Raises:TypeError – Raised if parameters are no the correct data type.
set_eventhandler(events)

Allows you to set the event handler.

Parameters:events (Events.Handler) – This should be an instance of a class that inherits from Events.Handler . Normally, you shouldn’t have to use this as the bot will do this for you, but this is here to give you more control over the bot if you want to do something very specific.
Raises:TypeError – Raised if parameters are no the correct data type.
set_file_logger(logger)

See Logger.Logger.set_console_logger()

Raises:TypeError – Raised if parameters are no the correct data type.

Websocket Module

class TwitchPy.Websocket.IRC(logger, commands, events, token: str, user: str, channel: str, chatlimit: int)

Handles the IRC connection to twitch chat.

Is responsible for reading and sending messages and selecting which commands to execute.

Reference: https://dev.twitch.tv/docs/irc/guide

Parameters:
  • logger (Logger.Logger) – The bot’s custom logger.
  • commands ((Commands.Cog)) – A set of all the command cogs.
  • events (Event.Handler) – The event handler.
  • token (str) – The bot’s oauth token.
  • user (str) – The bot’s username.
  • channel (str) – The channel to connect to.
  • chatlimit (int) – The maximum number of chat messages that chat_history attribute should hold on to. If chat_history becomes full (number of messages equals or exceeds chatlimit), delete messages to make space for newer ones.
Variables:
basic_send(msg: str)

Sends a message to the twitch IRC at it’s most basic level.

Note

This isn’t for sending messages to twitch chat. For that use Websocket.IRC.send()

Parameters:msg (str) – The message that IRC is expecting like ‘CAP REQ :twitch.tv/tags twitch.tv/commands twitch.tv/membership’. Note: you do not need to convert this to bytes.
Raises:TypeError – Raised if parameters are not the correct data type.
connect()

Connects to and sends twitch IRC all the info it needs to connect to chat with appropriate permissions

disconnect()

Closes all connections to twitch IRC.

listen()

An infinite loop that listens to twitch chat.

Also responsible for parsing chat messages and deciding which commands to execute (if any).

send(msg: str)

Sends a message to twitch chat.

Parameters:msg (str) – The message that you want to show up in twitch chat.
Raises:TypeError – Raised if parameters are not the correct data type.

API Module

class TwitchPy.API.Helix(logger, channel: str, cid: str)

Handles calls to Twitch’s New API: Helix

Reference: https://dev.twitch.tv/docs/api/reference

Parameters:
  • logger (Logger) – Logger to log things as they happen. Useful for debugging.
  • channel (str) – The name of the channel that the bot connects to.
  • cid (str) – The bot’s client ID.

Note

You should’t have to make an instance of this class.

follows_me(user_id: str) → bool

Checks to see if a viewer is following the broadcaster.

Reference: https://dev.twitch.tv/docs/api/reference#get-users-follows

Parameters:user_id (str) – The user ID of the viewer whose follow status you want to know.
Returns:bool – True if the viewer does follow you. False if they don’t.
Raises:TypeError – Raised if user_id parameter is not a string
get_endpoint(endpoint: str) → dict

Lets you get any endpoint in the API.

Also translates the response into a dict via json. Reference: https://dev.twitch.tv/docs/api/reference

Parameters:endpoint (str) –

The part of the endpoint link after ‘twitch.tv/helix’.

note: MUST start with ‘/’

ex: GOOD ‘/users?login=someviewer’

BAD ‘user?login=someviewer’

BAD ‘https:api.twitch.tv/helix/user?login=someviewer

Returns:dict – The data received from the endpoint in dict format.
Raises:TypeError – Raised if endpoint parameter is not a string
get_my_followers() -> (<class 'str'>, <class 'str'>)

Gets all the viewers who follow the broadcaster.

reference: https://dev.twitch.tv/docs/api/reference#get-users-follows

Returns:tuple – contains tuples whose first elements are usernames and second elements are user IDs.
get_user_info(user: str) → list

Gets viewer info based on either their username or id.

Reference: https://dev.twitch.tv/docs/api/reference#get-users

Parameters:user (str or [str]) –

A list of strings of viewers to get info on. These strings can be the viewers’ usernames or user IDs or a mixture of both.

note: they MUST be strings, even though their user ID might be an int.

Returns:list – An example: [{'broadcaster_type': 'affiliate', 'description': 'example ' 'description ', 'display_name': 'johndoe', 'id': '1234567890', 'login': 'johndoe', 'offline_image_url': 'url here', 'profile_image_url': 'url here', 'type': 'staff', 'view_count': 12345}]
Raises:TypeError – Raised if any element in user parameter is not a str
get_viewers() → dict

Gets all viewers who are currently in chat

Returns:list – A list of strings whose elements are users in chat.

Note

An example of what we get: ``{“_links”: {}, “chatter_count”: 1, “chatters”: {“broadcaster”: [“broadcaster username”], “vips”: [],
“moderators”: [“mod1”], “staff”: [], “admins”: [], “global_mods”: [], “viewers”: [“viewer1”, “viewer2”]}}``

Note

This is not a Helix endpoint and does not call get_endpoint()

ChatInfo Module

class TwitchPy.ChatInfo.Chat(channel: str)

Parses and holds basic information about the chat message being sent.

An object of this gets instantiated whenever a viewer sends a message through the IRC chat.

Parameters:

channel (str) – The channel that the bot is connected to.

Variables:
  • channel (str) – See parameters.
  • tags (dict) –

    Tags associated with the message.

    See https://dev.twitch.tv/docs/irc/tags#privmsg-twitch-tags

  • raw_message (str) –

    The raw message received from IRC. This is probably not what you want to be accessing unless you know what you’re looking for.

    ex: @badge-info=subscriber/12;badges=subscriber/12,premium/1;color=#FF0000; … PRIVMSG #someviewer :!foobar lorem ipsum’

  • msg (str) –

    The actual message that you would see on twitch chat.

    ex: ‘!foobar lorem ipsum’

  • arg_msg (str) –

    msg without the command prefix or command name.

    ex: ‘lorem ipsum’

  • args ([str]) –

    arg_msg split by spaces. This is what you’ll probably use the most in your commands.

    ex: [‘lorem’, ‘ipsum’]

  • author (User) – Object containing basic information about the viewer who sent the message

Note

You shouldn’t have to make an instance of this class.

get_channel() → str
get_full_args() → str
get_msg() → str
get_split_args() → [<class 'str'>]
get_tags() → dict
get_user() → TwitchPy.UserInfo.User

UserInfo

class TwitchPy.UserInfo.User(name: str, uid: str, broadcaster: bool, moderator: bool, subscriber: bool, sub_length: int, badges: [<class 'str'>])

More or less just a container to hold information on the viewer who sent a message.

Parameters:
  • name (str) – The username of the viewer.
  • uid (str) – The user ID of the viewer.
  • broadcaster (bool) – True if this viewer is the broadcaster (streamer).
  • moderator (bool) – True if this viewer is a moderator of the channel.
  • subscriber (bool) – True if this viewer is a subscriber of the channel.
  • sub_legnth (int) – If the viewer is a subscriber, how long in months they’ve been subscribed. If they are not a subscriber, this will be 0.
  • badges ([str]) – A list of all the chat badges the viewer has.
Variables:

Parameters (See) –

Note

Does not keep track of follower status because that requries an API call.