feat(examples): add new examples about CV2#1419
Open
Snipy7374 wants to merge 2 commits intoDisnakeDev:masterfrom
Open
feat(examples): add new examples about CV2#1419Snipy7374 wants to merge 2 commits intoDisnakeDev:masterfrom
Snipy7374 wants to merge 2 commits intoDisnakeDev:masterfrom
Conversation
Enegg
reviewed
Nov 8, 2025
| websites: list[Website] = await fetch_websites() | ||
| web_components = [ | ||
| ui.Section( | ||
| ui.TextDisplay("### " + website.name), |
Contributor
There was a problem hiding this comment.
Suggested change
| ui.TextDisplay("### " + website.name), | |
| ui.TextDisplay(f"### {website.name}"), |
Comment on lines
+170
to
+171
| last_page_size = len(data) % TODO_PER_PAGE | ||
| total_pages = len(data) // TODO_PER_PAGE |
Contributor
There was a problem hiding this comment.
Suggested change
| last_page_size = len(data) % TODO_PER_PAGE | |
| total_pages = len(data) // TODO_PER_PAGE | |
| total_pages, last_page_size = divmod(len(data), TODO_PER_PAGE) |
Comment on lines
+200
to
+201
| # ideally you don't do this for every button click, you just do it the first time | ||
| # then cache it and reuse |
Comment on lines
+272
to
+379
| @bot.listen(disnake.Event.button_click) | ||
| async def back_btn(inter: disnake.MessageInteraction) -> None: | ||
| if not inter.component.custom_id: | ||
| return | ||
|
|
||
| # remember that this is a normal listener and will get called | ||
| # for every global button click so we ignore every other component | ||
| # except for the one we really care (todo_back_btn) | ||
| if not inter.component.custom_id.startswith("todo_back_btn"): | ||
| return | ||
|
|
||
| # we get our data from the button custom id that we built previously | ||
| invoker_id, current_page, total_pages, last_page_size = map( | ||
| int, inter.component.custom_id.split(":")[1:] | ||
| ) | ||
| await interaction_check(inter, invoker_id, inter.author.id) | ||
|
|
||
| # we implement a pac-man like effect, if you are at the first page | ||
| # it will bring you at the last page | ||
| if current_page == 0: | ||
| current_page = total_pages - 1 | ||
| else: | ||
| current_page -= 1 | ||
|
|
||
| await send_page(inter, current_page, total_pages, last_page_size) | ||
|
|
||
|
|
||
| @bot.listen(disnake.Event.button_click) | ||
| async def fast_back_btn(inter: disnake.MessageInteraction) -> None: | ||
| if not inter.component.custom_id: | ||
| return | ||
|
|
||
| if not inter.component.custom_id.startswith("todo_f_back_btn"): | ||
| return | ||
|
|
||
| # remember that this is a normal listener and will get called | ||
| # for every global button click so we ignore every other component | ||
| # except for the one we really care (todo_next_btn) | ||
| invoker_id, current_page, total_pages, last_page_size = map( | ||
| int, inter.component.custom_id.split(":")[1:] | ||
| ) | ||
| await interaction_check(inter, invoker_id, inter.author.id) | ||
|
|
||
| # bring the user to the first page | ||
| current_page = 0 | ||
| await send_page(inter, current_page, total_pages, last_page_size) | ||
|
|
||
|
|
||
| @bot.listen(disnake.Event.button_click) | ||
| async def next_btn(inter: disnake.MessageInteraction) -> None: | ||
| if not inter.component.custom_id: | ||
| return | ||
|
|
||
| if not inter.component.custom_id.startswith("todo_next_btn"): | ||
| return | ||
|
|
||
| # remember that this is a normal listener and will get called | ||
| # for every global button click so we ignore every other component | ||
| # except for the one we really care (todo_next_btn) | ||
| invoker_id, current_page, total_pages, last_page_size = map( | ||
| int, inter.component.custom_id.split(":")[1:] | ||
| ) | ||
| await interaction_check(inter, invoker_id, inter.author.id) | ||
|
|
||
| # we implement a pac-man like effect, if you are at the last page | ||
| # it will bring you at the first page | ||
| if current_page == (total_pages - 1): | ||
| current_page = 0 | ||
| else: | ||
| current_page += 1 | ||
|
|
||
| await send_page(inter, current_page, total_pages, last_page_size) | ||
|
|
||
|
|
||
| @bot.listen(disnake.Event.button_click) | ||
| async def fast_next_btn(inter: disnake.MessageInteraction) -> None: | ||
| if not inter.component.custom_id: | ||
| return | ||
|
|
||
| if not inter.component.custom_id.startswith("todo_f_next_btn"): | ||
| return | ||
|
|
||
| # remember that this is a normal listener and will get called | ||
| # for every global button click so we ignore every other component | ||
| # except for the one we really care (todo_next_btn) | ||
| invoker_id, current_page, total_pages, last_page_size = map( | ||
| int, inter.component.custom_id.split(":")[1:] | ||
| ) | ||
| await interaction_check(inter, invoker_id, inter.author.id) | ||
|
|
||
| # bring the user to the last page | ||
| current_page = total_pages - 1 | ||
| await send_page(inter, current_page, total_pages, last_page_size) | ||
|
|
||
|
|
||
| @bot.listen(disnake.Event.button_click) | ||
| async def options_btn(inter: disnake.MessageInteraction) -> None: | ||
| if not inter.component.custom_id: | ||
| return | ||
|
|
||
| if not inter.component.custom_id.startswith("todo_options"): | ||
| return | ||
|
|
||
| invoker_id, _ = map(int, inter.component.custom_id.split(":")[1:]) | ||
| await interaction_check(inter, invoker_id, inter.author.id) | ||
| await inter.send( | ||
| "Implement this logic yourself! You should now understand how this works.", ephemeral=True | ||
| ) |
Contributor
There was a problem hiding this comment.
I don't see a point in having a separate listener for each subcomponent
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
If someone wonders how the paginator looks like:

Let me know if this is too complex or if I should add more comments or if I should cover even more new components
Checklist
uv run nox -s lintuv run nox -s pyright