robertwayne / dpymenus

Simplified menus for discord.py developers.
https://dpymenus.com/
MIT License
26 stars 4 forks source link

Error when calling `menu.close()` / `menu.close()` not removing reactions (v2.0.0) #54

Closed RaymondLWong closed 3 years ago

RaymondLWong commented 3 years ago

I only saw the error once but calling menu.close() doesn't remove the reactions. In subsequent tests, I saw no error but the reactions still stayed. The menu does stop working afterwards though. From the error, it looks like there might be some leftover multi-session code?

Code excerpt:

async def create_paginated_entry(context: Context):
    def get_page() -> Page:
        current_page = Page(
            title="title",
        )
        return current_page

    async def update_data(menu: ButtonMenu):
        if menu.button_pressed(NavButton.stop):
            return await menu.close()
        await menu.output.edit(embed=get_page().as_safe_embed())

    button_menu = ButtonMenu(context) \
        .add_pages([get_page()]) \
        .set_timeout(default_menu_timeout) \
        .show_command_message() \
        .persist_on_close()
    await button_menu.open()

Error:

Ignoring exception in command xxx x:
Traceback (most recent call last):
  File "C:\Users\username\Documents\GitHub\projectname\venv\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "C:\Users\username\Documents\GitHub\projectname\src\xxx\x.py", line 695, in x
    await create_paginated_x_entry(context, x, user, False, args)
  File "C:\Users\username\Documents\GitHub\projectname\src\xxx\x.py", line 138, in create_paginated_x_entry
    await button_menu.open()
  File "C:\Users\username\Documents\GitHub\projectname\venv\lib\site-packages\dpymenus\button_menu.py", line 87, in open
    await self.page.on_next_event(self)
  File "C:\Users\username\Documents\GitHub\projectname\src\xxx\x.py", line 129, in update_data
    return await menu.close()
  File "C:\Users\username\Documents\GitHub\projectname\venv\lib\site-packages\dpymenus\base_menu.py", line 162, in close
    Session.get(self.ctx).kill_or_freeze()
AttributeError: 'NoneType' object has no attribute 'kill_or_freeze'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\username\Documents\GitHub\projectname\venv\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Users\username\Documents\GitHub\projectname\venv\lib\site-packages\discord\ext\commands\core.py", line 1348, in invoke
    await ctx.invoked_subcommand.invoke(ctx)
  File "C:\Users\username\Documents\GitHub\projectname\venv\lib\site-packages\discord\ext\commands\core.py", line 863, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "C:\Users\username\Documents\GitHub\projectname\venv\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'NoneType' object has no attribute 'kill_or_freeze'
robertwayne commented 3 years ago

Yeah this will be fixed today. Some of the settings weren't properly wired up!

Thank you for letting me know!

robertwayne commented 3 years ago

You can open this back up if you encounter any other issues. I am pretty sure I fished out all the bugs, but there's so many settings it's possible I missed something.

Thanks again!