7
7
import discord_typings
8
8
9
9
import interactions .models .discord as d_models
10
- from interactions .models .discord .snowflake import Snowflake
10
+ from interactions .models .discord .snowflake import Snowflake , Snowflake_Type
11
11
from interactions .client .const import ACTION_ROW_MAX_ITEMS , MISSING
12
12
from interactions .client .mixins .serialization import DictSerializationMixin
13
13
from interactions .models .discord .base import DiscordObject
@@ -212,6 +212,7 @@ class Button(InteractiveComponent):
212
212
label optional[str]: The text that appears on the button, max 80 characters.
213
213
emoji optional[Union[PartialEmoji, dict, str]]: The emoji that appears on the button.
214
214
custom_id Optional[str]: A developer-defined identifier for the button, max 100 characters.
215
+ sku_id: Optional[Snowflake_Type]: Identifier for a purchasable SKU, only available when using premium-style buttons
215
216
url Optional[str]: A url for link-style buttons.
216
217
disabled bool: Disable the button and make it not interactable, default false.
217
218
@@ -226,13 +227,15 @@ def __init__(
226
227
label : str | None = None ,
227
228
emoji : "PartialEmoji | None | str" = None ,
228
229
custom_id : str | None = None ,
230
+ sku_id : Snowflake_Type | None = None ,
229
231
url : str | None = None ,
230
232
disabled : bool = False ,
231
233
) -> None :
232
234
self .style : ButtonStyle = ButtonStyle (style )
233
235
self .label : str | None = label
234
236
self .emoji : "PartialEmoji | None" = emoji
235
237
self .custom_id : str | None = custom_id
238
+ self .sku_id : Snowflake_Type | None = sku_id
236
239
self .url : str | None = url
237
240
self .disabled : bool = disabled
238
241
@@ -244,10 +247,17 @@ def __init__(
244
247
if self .url is None :
245
248
raise ValueError ("URL buttons must have a url." )
246
249
250
+ elif self .style == ButtonStyle .PREMIUM :
251
+ if any (p is not None for p in (self .custom_id , self .url , self .emoji , self .label )):
252
+ raise ValueError ("Premium buttons cannot have a custom_id, url, emoji, or label." )
253
+ if self .sku_id is None :
254
+ raise ValueError ("Premium buttons must have a sku_id." )
255
+
247
256
elif self .custom_id is None :
248
257
self .custom_id = str (uuid .uuid4 ())
249
- if not self .label and not self .emoji :
250
- raise ValueError ("Buttons must have a label or an emoji." )
258
+
259
+ if self .style != ButtonStyle .PREMIUM and not self .label and not self .emoji :
260
+ raise ValueError ("Non-premium buttons must have a label or an emoji." )
251
261
252
262
if isinstance (self .emoji , str ):
253
263
self .emoji = PartialEmoji .from_str (self .emoji )
@@ -261,12 +271,13 @@ def from_dict(cls, data: discord_typings.ButtonComponentData) -> "Button":
261
271
label = data .get ("label" ),
262
272
emoji = emoji ,
263
273
custom_id = data .get ("custom_id" ),
274
+ sku_id = data .get ("sku_id" ),
264
275
url = data .get ("url" ),
265
276
disabled = data .get ("disabled" , False ),
266
277
)
267
278
268
279
def __repr__ (self ) -> str :
269
- return f"<{ self .__class__ .__name__ } type={ self .type } style={ self .style } label={ self .label } emoji={ self .emoji } custom_id={ self .custom_id } url={ self .url } disabled={ self .disabled } >"
280
+ return f"<{ self .__class__ .__name__ } type={ self .type } style={ self .style } label={ self .label } emoji={ self .emoji } custom_id={ self .custom_id } sku_id= { self . sku_id } url={ self .url } disabled={ self .disabled } >"
270
281
271
282
def to_dict (self ) -> discord_typings .ButtonComponentData :
272
283
emoji = self .emoji .to_dict () if self .emoji else None
@@ -279,6 +290,7 @@ def to_dict(self) -> discord_typings.ButtonComponentData:
279
290
"label" : self .label ,
280
291
"emoji" : emoji ,
281
292
"custom_id" : self .custom_id ,
293
+ "sku_id" : self .sku_id ,
282
294
"url" : self .url ,
283
295
"disabled" : self .disabled ,
284
296
}
0 commit comments