Canary is a Python3 bot designed for the McGill University Community Discord Server. The bot provides helper functions to users, as well as fun functions, a quote database and custom greeting messages.
Paginator has an error when called with empty item_list and display option 3 (Embed, list of strings).
The desired outcome with these input params would be that it displays an empty embed page, with the regular title and page 01 of 01 at the bottom.
Reproduction Steps
Call paginate with a Pages instance using display option 3 (Embed, list of strings), and an empty item_list.
p = Pages(ctx,
item_list=[],
display_option=(3,10))
p.paginate()
Potential Reasons behind Bug:
It seems to be crashing due to a discord-internal embed.to_dict call, as the pages_to_send variable is of type str, and when the internal call to_dict is made it throws the error as seen below.
In function organize_embeds_list the loop for populating the pages_to_send variable runs for i in range(page_counter), where page_counter is set on line 158 with math.ceil(len(self.itemList) / item_per_page). With the specified input params this obviously becomes zero, and thus the loop never runs, meaning the pages_to_send list is left empty and of type str.
Additional Context:
File "....local/share/virtualenvs/Canary-SrZpbO93/lib/python3.6/site-packages/discord/ext/commands/core.py", line 79, in wrapped ret = await coro(*args, **kwargs) File ".../Canary/cogs/info.py", line 66, in inrole await p.paginate() File ".../Canary/cogs/utils/paginator.py", line 247, in paginate await self._show_page(self.currentPage) File ".../Canary/cogs/utils/paginator.py", line 206, in _show_page embed=self.pagesToSend[self.currentPage], delete_after=300) File ".../.local/share/virtualenvs/Canary-SrZpbO93/lib/python3.6/site-packages/discord/abc.py", line 795, in send embed = embed.to_dict() AttributeError: 'str' object has no attribute 'to_dict'
Bug Description
Paginator has an error when called with empty
item_list
and display option 3 (Embed, list of strings). The desired outcome with these input params would be that it displays an empty embed page, with the regular title andpage 01 of 01
at the bottom.Reproduction Steps
Call paginate with a Pages instance using display option 3 (Embed, list of strings), and an empty item_list.
Potential Reasons behind Bug:
It seems to be crashing due to a discord-internal embed.to_dict call, as the
pages_to_send
variable is of type str, and when the internal call to_dict is made it throws the error as seen below.In function
organize_embeds_list
the loop for populating thepages_to_send
variable runsfor i in range(page_counter)
, wherepage_counter
is set on line 158 withmath.ceil(len(self.itemList) / item_per_page)
. With the specified input params this obviously becomes zero, and thus the loop never runs, meaning thepages_to_send
list is left empty and of type str.Additional Context:
File "....local/share/virtualenvs/Canary-SrZpbO93/lib/python3.6/site-packages/discord/ext/commands/core.py", line 79, in wrapped ret = await coro(*args, **kwargs) File ".../Canary/cogs/info.py", line 66, in inrole await p.paginate() File ".../Canary/cogs/utils/paginator.py", line 247, in paginate await self._show_page(self.currentPage) File ".../Canary/cogs/utils/paginator.py", line 206, in _show_page embed=self.pagesToSend[self.currentPage], delete_after=300) File ".../.local/share/virtualenvs/Canary-SrZpbO93/lib/python3.6/site-packages/discord/abc.py", line 795, in send embed = embed.to_dict() AttributeError: 'str' object has no attribute 'to_dict'