Twitch Bot Repeating Timed Loop - Python

So, I have a bot written in python, and I can not seem to get a loop going. What I want to do is have the bot say something in chat every X amount of seconds. For example, let’s say every 10 minutes, so every 600 seconds, I want the bot to say something.

I tried to start a function to do this with asyncio but I keep getting an error saying it’s unable to respond to echo messages.

Any help is greatly appreciated.

Here’s the relevant code I have (I removed the extra functions and such that already work:

`
import os
from twitchio.ext import commands

set up the bot

TMI_TOKEN=“omitted oauth”
CLIENT_ID=“omitted client id”
BOT_NICK=“bot_name”
BOT_PREFIX="!"
CHANNEL=“channel_name”

bot = commands.Bot(
irc_token=TMI_TOKEN,
client_id=CLIENT_ID,
nick=BOT_NICK,
prefix=BOT_PREFIX,
initial_channels=[CHANNEL]
)

@bot.event
async def event_ready():
print(f"{BOT_NICK} is alive!")
ws = bot._ws
await ws.send_privmsg(CHANNEL, f"/me is alive!")

@bot.event
async def event_message(ctx):
# make sure the bot ignores itself and the streamer
if ctx.author.name.lower() == BOT_NICK.lower():
return

await bot.handle_commands(ctx)

if 'hi' in ctx.content.lower():
    await ctx.channel.send(f"Hi, @{ctx.author.name}!")

@bot.command(name=“looper”)
async def looper(ctx):
#this is the function I want to run on a loop
start_forever_function() #or start forever function when bot is ready

async def start_forever_function():
await chan.send("Message " + str(time.gmtime()))

if name == “main”:
bot.run()

`

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