modmail-dev / Modmail

A Discord bot that functions as a shared inbox between staff and members, similar to Reddit's Modmail.
https://docs.modmail.dev
GNU Affero General Public License v3.0
1.58k stars 4.59k forks source link

[BUG]: USER Issue causing bug #3354

Open auyylaso opened 3 weeks ago

auyylaso commented 3 weeks ago

Bot Version

4.1.0

How are you hosting Modmail?

PM2

Error Logs

Check additional info

Screenshots

No response

Additional Information

0|modmail  | 11/05/24 10:15:24 core.config[295] - INFO: Setting level_permissions.
0|modmail  | 11/05/24 10:15:24 __main__[1122] - INFO: Updating permissions for SUPPORTER, 1293175166150639667 (add=True).
0|modmail  | 11/05/24 10:15:24 cogs.utility[1350] - INFO: Granting Chaos Mod access to Modmail category.
0|modmail  | 11/05/24 10:15:24 __main__[1555] - ERROR: Unexpected exception:
0|modmail  | Traceback (most recent call last):
0|modmail  |   File "/root/.local/share/virtualenvs/modmail-R5e9Y0tA/lib/python3.10/site-packages/discord/ext/commands/core.py", line 235,                                                                                 in wrapped
0|modmail  |     ret = await coro(*args, **kwargs)
0|modmail  |   File "/home/hehe/modmail/cogs/utility.py", line 1351, in permissions_add
0|modmail  |     await self.bot.main_category.set_permissions(key, read_messages=True)
0|modmail  | AttributeError: 'NoneType' object has no attribute 'set_permissions'
0|modmail  | The above exception was the direct cause of the following exception:
0|modmail  | Traceback (most recent call last):
0|modmail  |   File "/root/.local/share/virtualenvs/modmail-R5e9Y0tA/lib/python3.10/site-packages/discord/ext/commands/bot.py", line 1350,                                                                                 in invoke
0|modmail  |     await ctx.command.invoke(ctx)
0|modmail  |   File "/root/.local/share/virtualenvs/modmail-R5e9Y0tA/lib/python3.10/site-packages/discord/ext/commands/core.py", line 1650                                                                                , in invoke
0|modmail  |     await ctx.invoked_subcommand.invoke(ctx)
0|modmail  |   File "/root/.local/share/virtualenvs/modmail-R5e9Y0tA/lib/python3.10/site-packages/discord/ext/commands/core.py", line 1029                                                                                , in invoke
0|modmail  |     await injected(*ctx.args, **ctx.kwargs)  # type: ignore
0|modmail  |   File "/root/.local/share/virtualenvs/modmail-R5e9Y0tA/lib/python3.10/site-packages/discord/ext/commands/core.py", line 244,                                                                                 in wrapped
0|modmail  |     raise CommandInvokeError(exc) from exc
0|modmail  | discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'NoneType' object has no attribu                                                                                te 'set_permissions'

If you delete the main_category_id on discord side without updating it in the config command it will cause the bot to throw this error when trying to set "perms add level (LEVEL) Role"

Very simple fix just add a check before trying to update perms in the event the user is an idiot like me :D I know nothing about this project otherwise I'd just make a PR plus I'm awful at python.

sebkuip commented 3 weeks ago

Well this is supposed to throw an error as this is unintentional behavior. Not sure what you expect a check to fix because the set permissions will fail anyways.

auyylaso commented 3 weeks ago

Just a catch that throws a message in the discord channel that the user is using. It's not needed but would be good to have some sort of feedback that isn't just terminal side.

The catch is already there for the exception. Maybe it's pointless but I'm more so thinking for the less technical savvy that may not know why the bot isn't setting permission and doesn't realize they can use ?debug to print the logs

raidensakura commented 3 weeks ago

Duplicate of #3275

auyylaso commented 3 weeks ago

Duplicate of #3275

Not exactly the one you posted is an error caused by a lack of permissions aka a 403 response the error that I posted is about a missing category making it so the bot can't change permissions.