brandons209 / Red-bot-Cogs

Cog for Discord Red-Bot to do various things
GNU General Public License v3.0
13 stars 4 forks source link

[personalrole] Exception error if list is empty when it had roles in the list prior #22

Closed kyle95wm closed 2 years ago

kyle95wm commented 2 years ago

I receive the following exception when trying to run the myrole list command when no roles are in the list when there were roles in the list prior


Traceback (most recent call last):
  File "/home/bot/redenv/lib/python3.8/site-packages/discord/ext/commands/core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "/home/bot/.local/share/Red-DiscordBot/data/proleman/cogs/CogManager/cogs/personalroles/personalroles.py", line 131, in mr_list
    await menu(ctx, pages, DEFAULT_CONTROLS)
  File "/home/bot/redenv/lib/python3.8/site-packages/redbot/core/utils/menus.py", line 59, in menu
    if not isinstance(pages[0], (discord.Embed, str)):
IndexError: list index out of range

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

Traceback (most recent call last):
  File "/home/bot/redenv/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 939, in invoke
    await ctx.command.invoke(ctx)
  File "/home/bot/redenv/lib/python3.8/site-packages/redbot/core/commands/commands.py", line 832, in invoke
    await super().invoke(ctx)
  File "/home/bot/redenv/lib/python3.8/site-packages/discord/ext/commands/core.py", line 1348, in invoke
    await ctx.invoked_subcommand.invoke(ctx)
  File "/home/bot/redenv/lib/python3.8/site-packages/discord/ext/commands/core.py", line 863, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "/home/bot/redenv/lib/python3.8/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: IndexError: list index out of range```

Hope this can be fixed in an update so that the bot catches these cases.
brandons209 commented 2 years ago

Hmm. not sure what you mean by what you said. So you add a role to someone, remove that role so they have no personal roles, then try myrole list?

kyle95wm commented 2 years ago

Pretty much. Let's say if one person in the entire server gets assigned a personal role. They would then be added to the list. When their role is removed and unassigned, the list would therefore be empty. When running myrole list however, instead of getting the "there are no personal roles assigned" message, I instead get that lovely traceback in my op. This should not happen.

brandons209 commented 2 years ago

Alright I see the problem. Seems like Redbot's config won't return an empty list for all member's data if someone has had a role before. Just added in an extra check in 62b4054a33a35eb4e4f145987c1c780a3fd966e3 and it seems to fix it.

kyle95wm commented 2 years ago

Yep it's all good now!