PythonistaGuild / TwitchIO

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

event_join user not returning user tags and gives error on checking for mod/sub #84

Closed SouDescolado closed 2 years ago

SouDescolado commented 5 years ago

Describe the bug While trying to grab user information when it joins the channel, it returns empty tags and gives error when trying to check for mod.

Are you using TwitchIO within a Discord Bot? No

What commit of TwitchIO are you using? pip show twitchio Version 2.0.0a1

To Reproduce Steps to reproduce the behaviour:

    async def event_join(self, channel, user):
        print(dir(user))
        print(f'User joined: ' + str(user.name))
        print(f'User tags: '  + str(user._tags))
        print(f'User is mod: '  + str(user.is_mod))

It returns

['__abstractmethods__', '__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__invalid__', '__le__', '__lt__', '__messageable_channel__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__slots__', '__str__', '__subclasshook__', '_abc_impl', '_bot', '_bot_is_mod', '_channel', '_colour', '_display_name', '_fetch_channel', '_fetch_websocket', '_mod', '_name', '_sub', '_tags', '_turbo', '_ws', 'channel', 'check_bucket', 'check_content', 'color', 'colour', 'display_name', 'id', 'is_mod', 'is_subscriber', 'is_turbo', 'name', 'send']
User joined: botdescolado
User tags: None
Task exception was never retrieved
future: <Task finished coro=<Bot.event_join() done, defined at D:/Python/Python37-32/bot.py:21> exception=AttributeError('_mod')>
Traceback (most recent call last):
  File "D:/Python/Python37-32/bot.py", line 25, in event_join
    print(f'User is mod: '  + str(user.is_mod))
  File "C:\Users\MOA\AppData\Roaming\Python\Python37\site-packages\twitchio\user.py", line 150, in is_mod
    if self._mod == 1:
AttributeError: _mod

Expected behaviour The same thing when you check during messages. With the code:

    @commands.command(name='test')
    async def test(self, ctx):
        print(dir(ctx.author))
        print(f'User joined: ' + str(ctx.author.name))
        print(f'User tags: '  + str(ctx.author._tags))
        print(f'User is mod: '  + str(ctx.author.is_mod))

It returns

['__abstractmethods__', '__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__invalid__', '__le__', '__lt__', '__messageable_channel__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__slots__', '__str__', '__subclasshook__', '_abc_impl', '_bot', '_bot_is_mod', '_channel', '_colour', '_display_name', '_fetch_channel', '_fetch_websocket', '_mod', '_name', '_sub', '_tags', '_turbo', '_ws', 'channel', 'check_bucket', 'check_content', 'color', 'colour', 'display_name', 'id', 'is_mod', 'is_subscriber', 'is_turbo', 'name', 'send']
User joined: soudescolado
User tags: {'@badge-info': 'subscriber/1', 'badges': 'broadcaster/1,subscriber/0,sub-gifter/1', 'color': '#0000FF', 'display-name': 'SouDescolado', 'emotes': '', 'flags': '', 'id': '81dba407-0b76-436a-930a-2562e90c17b5', 'mod': '0', 'room-id': '37497308', 'subscriber': '1', 'tmi-sent-ts': '1567101602103', 'turbo': '0', 'user-id': '37497308', 'user-type': ''}
User is mod: True

Screenshots None needed I think

(please complete the following information):

Additional context Also, there is a lack of the "badges" attribute on user, and the documentation mentions that event_join just need the user, when it actually needs both channel and user

EvieePy commented 5 years ago

Unfortunately JOIN events don't have tags sent with them. So what you get is a Partial User, though thanks for finding the bug in is_mod, that shouldn't error.

Also you are using 2.0 which is currently in alpha status and does not have documentation. The documentation you are reading is from the previous release.