@@ -58,10 +58,10 @@ class Stream:
5858 The current stream ID.
5959 user: twitchio.PartialUser
6060 The user who is streaming.
61- game_id: str
62- Current game ID being played on the channel.
63- game_name: str
64- Name of the game being played on the channel.
61+ game_id: str | None
62+ Current game ID being played on the channel. Could be `None` if no category / game has been set.
63+ game_name: str | None
64+ Name of the game being played on the channel. Could be `None` if no category / game has been set.
6565 type: str
6666 Whether the stream is "live" or not.
6767 title: str
@@ -101,8 +101,8 @@ def __init__(self, data: StreamsResponseData, *, http: HTTPClient) -> None:
101101
102102 self .id : str = data ["id" ]
103103 self .user = PartialUser (data ["user_id" ], data ["user_login" ], data ["user_name" ], http = http )
104- self .game_id : str = data ["game_id" ]
105- self .game_name : str = data ["game_name" ]
104+ self .game_id : str | None = data ["game_id" ]
105+ self .game_name : str | None = data ["game_name" ]
106106 self .type : str = data ["type" ]
107107 self .title : str = data ["title" ]
108108 self .viewer_count : int = data ["viewer_count" ]
@@ -115,19 +115,25 @@ def __init__(self, data: StreamsResponseData, *, http: HTTPClient) -> None:
115115 def __repr__ (self ) -> str :
116116 return f"<Stream id={ self .id } user={ self .user } title={ self .title } started_at={ self .started_at } >"
117117
118- async def fetch_game (self ) -> Game :
118+ async def fetch_game (self ) -> Game | None :
119119 """Fetches the :class:`~twitchio.Game` associated with this stream.
120120
121121 The :class:`~twitchio.Game` returned is current from the time the :class:`~twitchio.Stream`
122122 instance was created.
123123
124+ Could be `None` if no category / game was set at the time the :class:`~twitchio.Stream`
125+ instance was created.
126+
124127 Returns
125128 -------
126- twitchio.Game
127- The game associated with this :class:`~twitchio.Stream` instance.
129+ twitchio.Game | None
130+ The game associated with this :class:`~twitchio.Stream` instance, or `None` .
128131 """
132+ if self .game_id is None :
133+ return None
134+
129135 payload : GamesResponse = await self ._http .get_games (ids = [self .game_id ])
130- return Game (payload ["data" ][0 ], http = self ._http )
136+ return Game (payload ["data" ][0 ], http = self ._http ) if payload [ "data" ] else None
131137
132138
133139class StreamMarker :
0 commit comments