diff --git a/discord/http.py b/discord/http.py index b247f9342..8f1d4e3f5 100644 --- a/discord/http.py +++ b/discord/http.py @@ -4249,7 +4249,7 @@ class HTTPClient: def get_trial_offer(self) -> Response[promotions.TrialOffer]: return self.request(Route('GET', '/users/@me/billing/user-trial-offer')) - def ack_trial_offer(self, trial_id: Snowflake) -> Response[None]: + def ack_trial_offer(self, trial_id: Snowflake) -> Response[promotions.TrialOffer]: return self.request(Route('POST', '/users/@me/billing/user-trial-offer/{trial_id}/ack', trial_id=trial_id)) def get_pricing_promotion(self) -> Response[promotions.WrappedPricingPromotion]: diff --git a/discord/promotions.py b/discord/promotions.py index 6f7337662..f039ea86a 100644 --- a/discord/promotions.py +++ b/discord/promotions.py @@ -224,8 +224,8 @@ class TrialOffer(Hashable): ---------- id: :class:`int` The ID of the trial offer. - expires_at: :class:`datetime.datetime` - When the trial offer expires. + expires_at: Optional[:class:`datetime.datetime`] + When the trial offer expires, if it has been acknowledged. trial_id: :class:`int` The ID of the trial. trial: :class:`SubscriptionTrial` @@ -242,15 +242,24 @@ class TrialOffer(Hashable): def __init__(self, *, data: TrialOfferPayload, state: ConnectionState) -> None: self._state = state + self._update(data) + def _update(self, data: TrialOfferPayload) -> None: self.id: int = int(data['id']) - self.expires_at: datetime = parse_time(data['expires_at']) + self.expires_at: Optional[datetime] = parse_time(data.get('expires_at')) self.trial_id: int = int(data['trial_id']) self.trial: SubscriptionTrial = SubscriptionTrial(data['subscription_trial']) def __repr__(self) -> str: return f'' + def is_acked(self) -> bool: + """:class:`bool`: Checks if the trial offer has been acknowledged. + + .. versionadded:: 2.1 + """ + return self.expires_at is not None + async def ack(self) -> None: """|coro| @@ -261,7 +270,8 @@ class TrialOffer(Hashable): HTTPException Acknowledging the trial offer failed. """ - await self._state.http.ack_trial_offer(self.id) + data = await self._state.http.ack_trial_offer(self.id) + self._update(data) class PricingPromotion: diff --git a/discord/types/promotions.py b/discord/types/promotions.py index e49d3877e..bdcb89f6a 100644 --- a/discord/types/promotions.py +++ b/discord/types/promotions.py @@ -57,7 +57,7 @@ class ClaimedPromotion(TypedDict): class TrialOffer(TypedDict): id: Snowflake - expires_at: str + expires_at: Optional[str] trial_id: Snowflake subscription_trial: SubscriptionTrial