interactions.py
interactions.py copied to clipboard
fix: select menu for paginators over 25 pages
Pull Request Type
- [ ] Feature addition
- [x] Bugfix
- [ ] Documentation update
- [ ] Code refactor
- [ ] Tests improvement
- [ ] CI/CD pipeline enhancement
- [ ] Other: [Replace with a description]
Description
This fix enables interactions.ext.paginators Paginator with over 25 pages to be used with a select menu, using a "scrolling window" of pages in the paginator select menu.
In this implementation, for a paginator with N pages where N > 25, the first entry in the menu starts moving forward starting Page 13, showing page options 2 to 26. The first entry stops moving forward on page N - 12; if a paginator has 40 pages, the select menu will show page options 16 to 40 starting Page 28.
Changes
- Edited option enumeration in the
Paginator.create_components()section creating the select menu component
Related Issues
#1603
Test Scenarios
Replace the number in range(40) with any number at least 26. The paginator should be sent without errors. Select menu should show only 25 entries, and the option for Page 1 should disappear starting Page 14.
On the other hand, if the number in range(40) is 25 or less, all page options should show, without disappearing options.
from interactions import Client, Embed, slash_command
from interactions.ext.paginators import Paginator
bot = Client()
@slash_command(name="test")
async def test_cmd(ctx):
embeds = [Embed(title=f"Page {i+1}") for i in range(40)]
paginator = Paginator.create_from_embeds(bot, *embeds)
paginator.show_select_menu = True
await paginator.send(ctx)
bot.start("token")
Python Compatibility
- [ ] I've ensured my code works on Python
3.10.x - [x] I've ensured my code works on Python
3.11.x
Checklist
- [x] I've run the
pre-commitcode linter over all edited files - [x] I've tested my changes on supported Python versions
- [ ] I've added tests for my code, if applicable
- [ ] I've updated / added documentation, where applicable