Skip to content

Conversation

@Snipy7374
Copy link
Collaborator

Summary

If someone wonders how the paginator looks like:
image

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

  • 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 uv run nox -s lint
    • I have type-checked the code by running uv run nox -s 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, ...)

@read-the-docs-community
Copy link

Documentation build overview

📚 disnake | 🛠️ Build #29831028 | 📁 Comparing d050bf6 against latest (4f4c308)


🔍 Preview build

Show files changed (51 files in total): 📝 51 modified | ➕ 0 added | ➖ 0 deleted
File Status
genindex.html 📝 modified
index.html 📝 modified
intro.html 📝 modified
whats_new.html 📝 modified
whats_new_legacy.html 📝 modified
api/abc.html 📝 modified
api/activities.html 📝 modified
api/app_commands.html 📝 modified
api/app_info.html 📝 modified
api/audit_logs.html 📝 modified
api/automod.html 📝 modified
api/channels.html 📝 modified
api/clients.html 📝 modified
api/components.html 📝 modified
api/emoji.html 📝 modified
api/entitlements.html 📝 modified
api/events.html 📝 modified
api/exceptions.html 📝 modified
api/guild_scheduled_events.html 📝 modified
api/guilds.html 📝 modified
api/integrations.html 📝 modified
api/interactions.html 📝 modified
api/invites.html 📝 modified
api/localization.html 📝 modified
api/members.html 📝 modified
api/messages.html 📝 modified
api/misc.html 📝 modified
api/permissions.html 📝 modified
api/roles.html 📝 modified
api/skus.html 📝 modified
api/soundboard.html 📝 modified
api/stage_instances.html 📝 modified
api/stickers.html 📝 modified
api/subscriptions.html 📝 modified
api/ui.html 📝 modified
api/users.html 📝 modified
api/utilities.html 📝 modified
api/voice.html 📝 modified
api/webhooks.html 📝 modified
api/widgets.html 📝 modified
ext/tasks/index.html 📝 modified
ext/commands/api/app_commands.html 📝 modified
ext/commands/api/bots.html 📝 modified
ext/commands/api/checks.html 📝 modified
ext/commands/api/cogs.html 📝 modified
ext/commands/api/context.html 📝 modified
ext/commands/api/converters.html 📝 modified
ext/commands/api/exceptions.html 📝 modified
ext/commands/api/help_commands.html 📝 modified
ext/commands/api/misc.html 📝 modified
ext/commands/api/prefix_commands.html 📝 modified

@Snipy7374 Snipy7374 changed the title featt(examples): add new examples about CV2 feat(examples): add new examples about CV2 Oct 6, 2025
@shiftinv shiftinv added t: documentation Improvements or additions to documentation/examples t: enhancement New feature skip news labels Oct 6, 2025
websites: list[Website] = await fetch_websites()
web_components = [
ui.Section(
ui.TextDisplay("### " + website.name),
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
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
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
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
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is that?

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
)
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see a point in having a separate listener for each subcomponent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip news t: documentation Improvements or additions to documentation/examples t: enhancement New feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants