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

feat(components): support premium buttons #1276

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

shiftinv
Copy link
Member

Summary

This adds support for premium buttons via ButtonStyle.premium and ui.Button.sku_id, and deprecates InteractionResponse.require_premium1.

discord/discord-api-docs@4853fbc

Checklist

  • If code changes were made, then they have been tested
    • I have updated the documentation to reflect the changes
    • I have formatted the code properly by running pdm lint
    • I have type-checked the code by running pdm pyright
  • This PR fixes an issue
  • This PR adds something new (e.g. new method or parameters)
  • This PR is a breaking change (e.g. methods or parameters removed/renamed)
  • This PR is not a code change (e.g. documentation, README, ...)

Footnotes

  1. Looks like this response type does not work at all anymore, contrary to the documentation and changelog, which claim "This will continue to function but may be eventually unsupported.". This makes it already a breaking change on Discord's end, so no point in making it even more breaking here. Still, it could honestly just be removed.

This updates the workaround added in 41618b1,
which attempts to preserve the row of url buttons. This already technically worked
for premium buttons too, but only due to a bug in that previous implementation.

Still, this remains an awful workaround. It may be easier to only update the components
directly, and leave `self.children` as is, ignoring additions/removals (which shouldn't happen here
in the first place). Alternatively, the new `id` field could also work, though it's currently still
part of that other thing and not public.
@shiftinv shiftinv added t: enhancement New feature t: api support Support of Discord API features t: deprecation Deprecation of existing features labels Jan 22, 2025
@shiftinv shiftinv added this to the disnake v2.11 milestone Jan 22, 2025
@Enegg
Copy link
Contributor

Enegg commented Jan 22, 2025

Can we please model SKU and URL buttons as distinct types 🙏

@@ -53,7 +53,7 @@ class Button(Item[V_co]):
The style of the button.
custom_id: Optional[:class:`str`]
The ID of the button that gets received during an interaction.
If this button is for a URL, it does not have a custom ID.
If this button is for a URL or an SKU, it does not have a custom ID.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
If this button is for a URL or an SKU, it does not have a custom ID.
If this button is for a URL or a SKU, it does not have a custom ID.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this was brought up at some point before; it depends on whether one pronounces "SKU" as individual letters (i.e. "S - K - U") or as one word (i.e. something like "skew"), and both are apparently valid:

I personally tend more towards the former pronounciation, and it's in line with the (admittedly few) occurrences already in the library, but the latter would be correct too, as far as I can tell.

disnake/ui/button.py Outdated Show resolved Hide resolved
@@ -169,7 +183,7 @@ def style(self, value: ButtonStyle) -> None:
def custom_id(self) -> Optional[str]:
"""Optional[:class:`str`]: The ID of the button that gets received during an interaction.

If this button is for a URL, it does not have a custom ID.
If this button is for a URL or an SKU, it does not have a custom ID.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
If this button is for a URL or an SKU, it does not have a custom ID.
If this button is for a URL or a SKU, it does not have a custom ID.

@@ -184,7 +184,7 @@ class Button(Component):
The style of the button.
custom_id: Optional[:class:`str`]
The ID of the button that gets received during an interaction.
If this button is for a URL, it does not have a custom ID.
If this button is for a URL or an SKU, it does not have a custom ID.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
If this button is for a URL or an SKU, it does not have a custom ID.
If this button is for a URL or a SKU, it does not have a custom ID.

Co-authored-by: Eneg <42005170+Enegg@users.noreply.github.com>
Signed-off-by: vi <8530778+shiftinv@users.noreply.github.com>
@Enegg
Copy link
Contributor

Enegg commented Jan 25, 2025

I suppose ActionRow.add_button should also be updated to work with SKUs

@shiftinv
Copy link
Member Author

I suppose ActionRow.add_button should also be updated to work with SKUs

yup, thanks! 0636ffe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
t: api support Support of Discord API features t: deprecation Deprecation of existing features t: enhancement New feature
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

2 participants