PythonistaGuild / TwitchIO

An Async Bot/API wrapper for Twitch made in Python.
https://twitchio.dev
MIT License
798 stars 162 forks source link

Bot.handle_commands() returns error for self-messages #197

Closed aticie closed 3 years ago

aticie commented 3 years ago

When making a child class of commands.Bot like this:

    async def event_message(self, message: Message):
        await self.handle_commands(message)
        ...  # Send message to channel for some commands

For the message that the bot sent to the channel, the Context() variable will be None. Thus producing this error:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/twitchio/client.py", line 176, in wrapped
    await func(*args)
  File "/src/bots/twitch_bot.py", line 71, in event_message
    await self.handle_commands(message)
  File "/usr/local/lib/python3.9/site-packages/twitchio/ext/commands/bot.py", line 253, in handle_commands
    context = await self.get_context(message)
  File "/usr/local/lib/python3.9/site-packages/twitchio/ext/commands/bot.py", line 223, in get_context
    return cls(message=message, prefix=prefix, valid=False, bot=self)
  File "/usr/local/lib/python3.9/site-packages/twitchio/ext/commands/core.py", line 388, in __init__
    self._ws = self.author._ws
AttributeError: 'NoneType' object has no attribute '_ws'
IAmTomahawkx commented 3 years ago

Don't handle ACK messages

aticie commented 3 years ago

Why did you close this with wontfix. This was literally the recommended way of doing it in 1.2.3.

async def event_message(self, message):
        print(message.content)
        await self.handle_commands(message)

from https://github.com/TwitchIO/TwitchIO/blob/1.2.3/docs/twitchio.rst

I don't understand why we need to add another if/else for self-messages now, it could be fixed in the library.

IAmTomahawkx commented 3 years ago

ACK messages cannot have an author because they are dispatched by the library. 2.0 has breaking changes from 1.x, this is one of those. Furthermore, you should not be handling messages from the bot anyways, so this is a wontfix.