Twitch Chat - PetterKraabol/Twitch-Python GitHub Wiki

twitch.Chat uses RxPY to deliver messages from Twitch IRC.

# Example
# Use Helix to retrieve user objects from live chat messages

import twitch


def handle_message(message: twitch.chat.Message) -> None:
    # print(message.channel, message.sender, message.text)
    user: twitch.helix.User = message.user()


helix = twitch.Helix('client-id', use_cache=True)

twitch.Chat(channel='#reckful', nickname='zarlach', oauth='oauth:xxxxxx', helix=helix).subscribe(handle_message)

Example bot

import twitch


def handle_message(message: twitch.chat.Message) -> None:
    if message.text.startswith('!views'):
        message.chat.send(f'@{message.user().display_name}, you have {message.user().view_count} views.')


def main():
    chat = twitch.Chat(channel='#zarlach',
                       nickname='bot',
                       oauth='oauth:xxxxxx',
                       helix=twitch.Helix(client_id='xxxxxx', use_cache=True))

    chat.subscribe(handle_message)


if __name__ == '__main__':
    main()
<zarlach> !views
<bot> @Zarlach, you have 1599 views.
⚠️ **GitHub.com Fallback** ⚠️