@@ -2424,7 +2424,7 @@ def websocket_subscriptions(self) -> dict[str, WebsocketSubscriptionData]:
24242424
24252425 return ret
24262426
2427- async def delete_websocket_subscription (self , id : str ) -> WebsocketSubscriptionData :
2427+ async def delete_websocket_subscription (self , id : str , * , force : bool = False ) -> WebsocketSubscriptionData :
24282428 """|coro|
24292429
24302430 Delete an EventSub subsctiption with a Websocket Transport.
@@ -2441,6 +2441,12 @@ async def delete_websocket_subscription(self, id: str) -> WebsocketSubscriptionD
24412441 ----------
24422442 id: str
24432443 The Eventsub subscription ID. You can view currently active subscriptions via :meth:`.websocket_subscriptions`.
2444+ force: bool
2445+ When set to ``True``, the subscription will be forcefully removed from the Client,
2446+ regardless of any HTTPException's raised during the call to Twitch.
2447+
2448+ When set to ``False``, if an exception is raised, the subscription will remain on the Client websocket.
2449+ Defaults to ``False``.
24442450
24452451 Returns
24462452 -------
@@ -2461,10 +2467,15 @@ async def delete_websocket_subscription(self, id: str) -> WebsocketSubscriptionD
24612467 if not sub :
24622468 continue
24632469
2464- await self ._http .delete_eventsub_subscription (id , token_for = token_for )
2465- socket ._subscriptions .pop (id , None )
2470+ try :
2471+ await self ._http .delete_eventsub_subscription (id , token_for = token_for )
2472+ except HTTPException as e :
2473+ if not force :
2474+ raise e
24662475
2476+ socket ._subscriptions .pop (id , None )
24672477 data = WebsocketSubscriptionData (sub )
2478+
24682479 if not socket ._subscriptions and not socket ._closing and not socket ._closed :
24692480 logger .info ("Closing websocket '%s' due to no remaining subscriptions." , socket )
24702481 await socket .close ()
0 commit comments