Hello, I have a question about the code. The twitchapi library.
What should I use to make the chatbot send a message to the chat every 15 minutes?
This is how I tried to implement it, but the bot does not send this message:
async def periodic_message(chat: Chat):
while True:
try:
await chat.send_message("unluckydayss", tgk)
await asyncio.sleep(900)
except Exception as e:
logger.error(f"Error: {e}")
await asyncio.sleep(60)
async def run_bot():
init_db()
target_scope = [AuthScope.CHAT_READ, AuthScope.CHAT_EDIT, AuthScope.CHANNEL_MANAGE_BROADCAST, AuthScope.MODERATOR_MANAGE_BANNED_USERS, AuthScope.CLIPS_EDIT]
auth = UserAuthenticator(twitch, target_scope, force_verify=False)
token, refresh_token = await auth.authenticate()
await twitch.set_user_authentication(token, target_scope, refresh_token)
chat = await Chat(twitch)
chat.register_event(ChatEvent.READY, on_ready)
chat.register_command("тг", telegramm)
chat.register_command("ваниш", vanishmessageforuser)
chat.register_command("казик", kazino)
chat.register_command("поиск", search_sound)
#chat.register_command("эло", check_elo)
#chat.register_command("смс", tgmes)
chat.register_event(ChatEvent.MESSAGE, on_message)
asyncio.create_task(periodic_message(chat))
chat.start()
try:
input("press ENTER to stop")
finally:
chat.stop()
await twitch.close()
asyncio.run(run_bot())