I'm trying to create a script that reads each channel point redemption in twitch, alongside a function that runs randomly. Reading through the docs I noticed there is something called Routines, but I have no idea how to implement this. Asynchronous code is not my forté and I'd really like some guidance on where to learn about this.
For example, I'm trying to put this: `
#asynchronous function that prints hello every 5 seconds
from twitchio.ext import routines
@routines.routine(seconds=5.0, iterations=5)
async def hello(arg: str):
print(f'Hello {arg}!')
hello.start('World')
`
Into this: `
#asynchronous function that reads channel point redeems
import twitchio
import asyncio
from twitchio.ext import pubsub
my_token = "..."
users_oauth_token = "..."
users_channel_id = 12345
client = twitchio.Client(token=my_token)
client.pubsub = pubsub.PubSubPool(client)
@client.event()
async def event_pubsub_bits(event: pubsub.PubSubBitsMessage):
pass # do stuff on bit redemptions
@client.event()
async def event_pubsub_channel_points(event: pubsub.PubSubChannelPointsMessage):
pass # do stuff on channel point redemptions
async def main():
topics = [
pubsub.channel_points(users_oauth_token)[users_channel_id],
pubsub.bits(users_oauth_token)[users_channel_id]
]
await client.pubsub.subscribe_topics(topics)
await client.start()
client.loop.run_until_complete(main())
`
If anyone has an idea of how to do this, I would love some assistance. Thank you
I haven't tried much yet, fairly clueless on how to start