TwitchIO Examples

Quick update with code that I'm using to respond to message with twitchio (opposed to !commands). The original code is further below, but somehtings not working with it anymore. (This is as of September, 2021)

So, this is what I'm doing now.

Something about the way this sends messages to chat is weird. Regular messages look like this when printed out by the script.

Messages from the bot look like:

Here are the old notes for reference. Some may work, but others won't.

## OLD NOTES - Some Of These Might Not Work

_I updated twitchio and keep getting `_ws` errors like:

Here are three ways to use TwitchIO to respond to commands, respond to messages, and to work without interaction.

(Note: I'm using `os.environ` in these examples, but I use `keyring` in my scripts. It uses the system credential store and is well worth a look if you're not familiar with it.)

### Respond To Commands

### Respond To Messages

This one responds to any message sent to the channel. Make sure to filter out message from the bot like I do here otherwise it'll create a loop talking to itself. That'll send messages as fast as it can which gets the bot timed out for an hour. (Ask me how I know...)

### Non-Interactive

This one posts a message as soon as the bot is connected and ready. No interaction required.

It also starts a loop that sets a message every 2 seconds (which is about as fast as Twitch allows). Note that the sleep is done with `asyncio.sleep`. Using `time.sleep` would block the script and it would never get out of `event_ready`. With the `asyncio.sleep` call other events can be processed (e.g. `event_message` will run for incoming messages.)