Skip to content

Commit

Permalink
Remove setting sku_id explicitly via button decorator
Browse files Browse the repository at this point in the history
Co-authored-by: Danny <1695103+Rapptz@users.noreply.github.com>
  • Loading branch information
DA-344 and Rapptz committed Jun 15, 2024
1 parent 9eac365 commit be9edf8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
19 changes: 8 additions & 11 deletions discord/ui/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ class Button(Item[V]):
For example, row=1 will show up before row=2. Defaults to ``None``, which is automatic
ordering. The row number must be between 0 and 4 (i.e. zero indexed).
sku_id: Optional[:class:`int`]
The SKU ID this button sends you to. Can't be combined with ``url``.
The SKU ID this button sends you to. Can't be combined with ``url``, ``label``, ``emoji``
nor ``custom_id``.
.. versionadded:: 2.4
"""
Expand Down Expand Up @@ -222,7 +223,8 @@ def sku_id(self) -> Optional[int]:

@sku_id.setter
def sku_id(self, value: Optional[int]) -> None:
self.style = ButtonStyle.premium
if value is not None:
self.style = ButtonStyle.premium
self._underlying.sku_id = value

@classmethod
Expand Down Expand Up @@ -265,7 +267,6 @@ def button(
style: ButtonStyle = ButtonStyle.secondary,
emoji: Optional[Union[str, Emoji, PartialEmoji]] = None,
row: Optional[int] = None,
sku_id: Optional[int] = None,
) -> Callable[[ItemCallbackType[V, Button[V]]], Button[V]]:
"""A decorator that attaches a button to a component.
Expand All @@ -275,11 +276,11 @@ def button(
.. note::
Buttons with a URL cannot be created with this function.
Buttons with a URL or an SKU cannot be created with this function.
Consider creating a :class:`Button` manually instead.
This is because buttons with a URL do not have a callback
This is because these buttons cannot have a callback
associated with them since Discord does not do any processing
with it.
with them.
Parameters
------------
Expand All @@ -303,10 +304,6 @@ def button(
like to control the relative positioning of the row then passing an index is advised.
For example, row=1 will show up before row=2. Defaults to ``None``, which is automatic
ordering. The row number must be between 0 and 4 (i.e. zero indexed).
sku_id: Optional[:class:`int`]
The SKU ID this button sends you to. Can't be combined with ``url``.
.. versionadded:: 2.4
"""

def decorator(func: ItemCallbackType[V, Button[V]]) -> ItemCallbackType[V, Button[V]]:
Expand All @@ -322,7 +319,7 @@ def decorator(func: ItemCallbackType[V, Button[V]]) -> ItemCallbackType[V, Butto
'label': label,
'emoji': emoji,
'row': row,
'sku_id': sku_id,
'sku_id': None,
}
return func

Expand Down
2 changes: 1 addition & 1 deletion docs/interactions/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ Enumerations
Represents a link button.
.. attribute:: premium

Represents a gradient button denoting that buying a SKU is
Represents a button denoting that buying a SKU is
required to perform this action.

.. versionadded:: 2.4
Expand Down

0 comments on commit be9edf8

Please sign in to comment.