Spam message every 8 minutes

Hi, how to implement one action that runs every 8 minutes?

async def spamtg(chatmes: ChatCommand):
    if chatmes.user.id == "..." or chatmes.user.mod or chatmes.user.id == br_id:
        await chatmes.reply("message")
        while True:
            await twitch.send_chat_announcement(br_id, mod_id, "message", "blue")
            await asyncio.sleep(480)

async def run_bot():
    init_db()
    target_scope = [...]

    token = "..."
    refresh_token = "..."

    await twitch.set_user_authentication(token, target_scope, refresh_token)
    chat = await Chat(twitch)

    chat.register_event(ChatEvent.READY, on_ready)
    chat.register_command("spamtg", spamtg)
    chat.register_event(ChatEvent.MESSAGE, on_message)
    ....

I tried to do it this way, but in this case you need to manually enable the launch of this action every time the bot is launched

Are there better solutions?

after successully join the room start your loop

Rather than start your loop on a command use the “joined room” to start the loop

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.