@@ -78,10 +78,14 @@ class Button(Item[V]):
78
78
79
79
.. warning::
80
80
81
- This parameter does not work with V2 components or with more than 25 items in your view .
81
+ This parameter does not work in :class:`ActionRow` .
82
82
83
83
id: Optional[:class:`int`]
84
84
The button's ID.
85
+ priority: Optional[:class:`int`]
86
+ Only works in :class:`ActionRow`. Any integer greater than 0. If specified, decides the position
87
+ of the button in this row instead of going by order of addition. The lower this number, the earlier its position.
88
+ The ActionRow's children will be reordered when the View containing this button is sent.
85
89
"""
86
90
87
91
__item_repr_attributes__ : tuple [str , ...] = (
@@ -94,6 +98,7 @@ class Button(Item[V]):
94
98
"row" ,
95
99
"custom_id" ,
96
100
"id" ,
101
+ "priority" ,
97
102
)
98
103
99
104
def __init__ (
@@ -108,6 +113,7 @@ def __init__(
108
113
sku_id : int | None = None ,
109
114
row : int | None = None ,
110
115
id : int | None = None ,
116
+ priority : int | None = None ,
111
117
):
112
118
super ().__init__ ()
113
119
if label and len (str (label )) > 80 :
@@ -120,11 +126,14 @@ def __init__(
120
126
raise TypeError ("cannot mix both url and sku_id with Button" )
121
127
if custom_id is not None and sku_id is not None :
122
128
raise TypeError ("cannot mix both sku_id and custom_id with Button" )
129
+ if priority and (priority < 0 or not isinstance (priority , int )):
130
+ raise ValueError ("priority must be an integer greater than 0" )
123
131
124
132
if not isinstance (custom_id , str ) and custom_id is not None :
125
133
raise TypeError (
126
134
f"expected custom_id to be str, not { custom_id .__class__ .__name__ } "
127
135
)
136
+ self .priority : int | None = priority
128
137
129
138
self ._provided_custom_id = custom_id is not None
130
139
if url is None and custom_id is None and sku_id is None :
@@ -294,6 +303,7 @@ def button(
294
303
emoji : str | GuildEmoji | AppEmoji | PartialEmoji | None = None ,
295
304
row : int | None = None ,
296
305
id : int | None = None ,
306
+ priority : int | None = None ,
297
307
) -> Callable [[ItemCallbackType [Button [V ]]], Button [V ]]:
298
308
"""A decorator that attaches a button to a component.
299
309
@@ -328,6 +338,15 @@ def button(
328
338
like to control the relative positioning of the row then passing an index is advised.
329
339
For example, row=1 will show up before row=2. Defaults to ``None``, which is automatic
330
340
ordering. The row number must be between 0 and 4 (i.e. zero indexed).
341
+
342
+ .. warning::
343
+
344
+ This parameter does not work in :class:`ActionRow`.
345
+
346
+ priority: Optional[:class:`int`]
347
+ Only works in :class:`ActionRow`. Any integer greater than 0. If specified, decides the position
348
+ of the button in this row instead of going by order of addition. The lower this number, the earlier its position.
349
+ The ActionRow's children will be reordered when the View containing it is sent. A priority of ``None`` will be ordered after any specified priority.
331
350
"""
332
351
333
352
def decorator (func : ItemCallbackType ) -> ItemCallbackType :
@@ -344,6 +363,7 @@ def decorator(func: ItemCallbackType) -> ItemCallbackType:
344
363
"emoji" : emoji ,
345
364
"row" : row ,
346
365
"id" : id ,
366
+ "priority" : priority
347
367
}
348
368
return func
349
369
0 commit comments