Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Premium Buttons #9864

Merged
merged 8 commits into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading