Skip to content

Conversation

@jrutschke
Copy link

Description

For some auto reward redemptions the current implementation threw an TypeError, as "message" in payload is None.
Changes account for payload["message"] to be None and depending attributes to be None (text, fragments, _emotes).

This also means, that text can be None in event_automatic_redemption_add.

Example payload for auto redemption of reward type "chosen_modified_sub_emote_unlock": payload message = None

{
'broadcaster_user_id': '63532168', 
'broadcaster_user_name': 'Elspeth', 
'broadcaster_user_login': 'elspeth', 
'user_id': '70182062', 
'user_name': 'Jacky_R', 
'user_login': 'jacky_r', 
'id': '9e8d188b-a319-4288-a63e-a799c307c2f9', 
'reward': {'type': 'chosen_modified_sub_emote_unlock', 'channel_points': 1000, 'emote': {'id': '1925385_SQ', 'name': 'speth1More_SQ'}},
'message': None, 
'redeemed_at': '2026-01-06T20:20:41.883998116Z'
}

Error before fix:

twitchio/models/eventsub_.py", line 3440, in __init__
    self.text: str = payload["message"]["text"]
                     ~~~~~~~~~~~~~~~~~~^^^^^^^^
TypeError: 'NoneType' object is not subscriptable

Example payload for auto redemption of reward type "send_highlighted_message" ===> payload message not None

{
'broadcaster_user_id': '63532168',
'broadcaster_user_name': 'Elspeth',
'broadcaster_user_login': 'elspeth',
'user_id': '70182062',
'user_name': 'Jacky_R',
'user_login': 'jacky_r',
'id': '7ce418fa-7a1c-4ddb-a4b5-3a9f6f2ca26e', 
'reward': {'type': 'send_highlighted_message', 'channel_points': 10000, 'emote': None},
'message': {'text': 'highlighting spethHi', 'fragments': [{'type': 'text', 'text': 'highlighting ', 'emote': None}, {'type': 'emote', 'text': 'spethHi', 'emote': {'id': '304266998'}}]},
'redeemed_at': '2026-01-10T10:13:29.348019308Z'
}

Checklist

  • If code changes were made then they have been tested.
    • I have updated the documentation to reflect the changes.
    • I have updated the changelog with a quick recap of my changes.
  • This PR fixes an issue.
  • This PR adds something new (e.g. new method or parameters).
  • This PR is a breaking change (e.g. methods or parameters removed/renamed)
  • This PR is not a code change (e.g. documentation, README, ...)
  • I have read and agree to the Developer Certificate of Origin for this contribution

@chillymosh
Copy link
Collaborator

chillymosh commented Jan 10, 2026

I'll test these changes when I get time, but you also need to update the types for the payloads from Twitch, because this current implementation shows:

Condition will always evaluate to True since the types "ChannelPointsMessageData" and "None" have no overlap

Once you have fixed that, you will have to adjust your changes in the model to account for it.

Does this change also account for both versions of this endpoint? v1 and v2 since v1 is not deprecated?

I do not agree with the changes of lists becoming optional and returning None. Those should return empty lists.

@jrutschke
Copy link
Author

V1 also still works with it, message is not None and text is empty 'message': {'text': '', 'emotes': None}

I'll check the ChannelPointsMessageData and change to return empty lists.

@chillymosh
Copy link
Collaborator

You can simply undo those commits and change them back to how they were.
It's only the text attribute that really needs updating, as it is a V2 change where it becomes Optional.

Although there is a discussion for it to return an empty string, as that is what it does for V1.

@jrutschke
Copy link
Author

jrutschke commented Jan 10, 2026

Not quite, as self._raw_emotes also throws the TypeError for message being None, and fragments.

@chillymosh
Copy link
Collaborator

My point being handling None privately and returning an empty string user side so there is no difference between v1 and v2 within the same model for that attribute. There are many examples in the library where we do not expose exactly what the API returns as we are not a wrapper, like many other "libraries" for Twitch.

I would also like input from @EvieePy on this discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants