Search code examples
pythonbotschattwitch

TwitchIO not recognizing the command used before


I am having the problem where if I run my bot, the first time I use a command, link !hello it send 'Hello (and the author)' back. But when I then try it again, it doesn't respond anymore. It does print in the console from the event_message. Then if I use another command like the !test, it gives response, but when I try that then again, it doesn't, but if I try !hello then, it works again, but only for that 1 time, until I used another command first.

Here's the code:


class Bot(commands.Bot):

    def __init__(self):
        super().__init__(token='MYTOKEN', prefix='!', initial_channels=['MYCHANNEL'])

    async def event_ready(self):
        print(f'Logged in as | {self.nick}')
        print(f'User id is | {self.user_id}')

    async def event_message(self, message):
        if message.echo:
            return

        print(message.content)
        await self.handle_commands(message)

    @commands.command()
    async def hello(self, ctx: commands.Context):
        await ctx.send(f'Hello {ctx.author.name}!')

    @commands.command()
    async def test(self, ctx: commands.Context):
        await ctx.send(f'test {ctx.author.name}!')

bot = Bot()
bot.run()```

Solution

  • I asked them in the discord. Giving the bot account moderator fixed the problem, since before it couldn't send the same message again too fast after each other