I'm setting up a python TwitchIO chat bot. The getting started example has this:
async def event_message(self, message):
print(message.content)
await self.handle_commands(message)
@commands.command(name='test')
async def my_command(self, ctx):
await ctx.send(f'Hello {ctx.author.name}!')
If the incoming message is a command (e.g. !test
), a message is sent back to the channel with ctx.send()
.
I'd like the option to send a message back to the channel (based on come criteria) whenever any message is received, not just commands. For example:
async def event_message(self, message):
print(message.content)
if SOMETHING:
SEND_MESSAGE_HERE
await self.handle_commands(message)
I can't figure out how to do some type of .send
to make that happen. This answer: TwitchIO: How to send a chat message? show this:
chan = bot.get_channel("channelname")
loop = asyncio.get_event_loop()
loop.create_task(chan.send("Send this message"))
I tried that and the bot sent a ton of messages instantly and got timed out for an hour.
So, the question is: How do you send a message back to the channel inside event_message