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

Include a message when failing to assign Discord permissions to users #3275

Open raidensakura opened 1 year ago

raidensakura commented 1 year ago

Is your feature request related to a problem? Please elaborate.

Right now, the bot just silently errors out when trying to set Discord permissions that the bot lacks, as follow:

And in the log file:

2023-04-08T05:22:50.557347269Z stdout F 04/08/23 05:22:50 core.config[292] - INFO: Setting level_permissions.
2023-04-08T05:22:50.558089959Z stdout F 04/08/23 05:22:50 __main__[1141] - INFO: Updating permissions for ADMINISTRATOR, 1005104021612277890 (add=True).
2023-04-08T05:22:50.577183806Z stdout F 04/08/23 05:22:50 cogs.utility[1364] - INFO: Granting Elysia access to Modmail category.
2023-04-08T05:22:50.740324959Z stdout F 04/08/23 05:22:50 __main__[1548] - ERROR: Unexpected exception:
2023-04-08T05:22:50.740355311Z stdout F Traceback (most recent call last):
2023-04-08T05:22:50.740360419Z stdout F   File "/usr/local/lib/python3.10/site-packages/discord/ext/commands/core.py", line 190, in wrapped
2023-04-08T05:22:50.740363947Z stdout F     ret = await coro(*args, **kwargs)
2023-04-08T05:22:50.740367406Z stdout F   File "/modmailbot/cogs/utility.py", line 1365, in permissions_add
2023-04-08T05:22:50.740370295Z stdout F     await self.bot.main_category.set_permissions(key, read_messages=True)
2023-04-08T05:22:50.740373773Z stdout F   File "/usr/local/lib/python3.10/site-packages/discord/abc.py", line 937, in set_permissions
2023-04-08T05:22:50.740376631Z stdout F     await http.edit_channel_permissions(
2023-04-08T05:22:50.740380269Z stdout F   File "/usr/local/lib/python3.10/site-packages/discord/http.py", line 738, in request
2023-04-08T05:22:50.74038304Z stdout F     raise Forbidden(response, data)
2023-04-08T05:22:50.740386034Z stdout F discord.errors.Forbidden: 403 Forbidden (error code: 50013): Missing Permissions
2023-04-08T05:22:50.740388852Z stdout F 
2023-04-08T05:22:50.740392122Z stdout F The above exception was the direct cause of the following exception:
2023-04-08T05:22:50.740394754Z stdout F 
2023-04-08T05:22:50.740397056Z stdout F Traceback (most recent call last):
2023-04-08T05:22:50.740399946Z stdout F   File "/usr/local/lib/python3.10/site-packages/discord/ext/commands/bot.py", line 1347, in invoke
2023-04-08T05:22:50.740403046Z stdout F     await ctx.command.invoke(ctx)
2023-04-08T05:22:50.740405969Z stdout F   File "/usr/local/lib/python3.10/site-packages/discord/ext/commands/core.py", line 1605, in invoke
2023-04-08T05:22:50.740409486Z stdout F     await ctx.invoked_subcommand.invoke(ctx)
2023-04-08T05:22:50.740413278Z stdout F   File "/usr/local/lib/python3.10/site-packages/discord/ext/commands/core.py", line 986, in invoke
2023-04-08T05:22:50.740416256Z stdout F     await injected(*ctx.args, **ctx.kwargs)  # type: ignore
2023-04-08T05:22:50.740418995Z stdout F   File "/usr/local/lib/python3.10/site-packages/discord/ext/commands/core.py", line 199, in wrapped
2023-04-08T05:22:50.740437312Z stdout F     raise CommandInvokeError(exc) from exc

Describe the solution you'd like

The bot should inform the user with a missing permission error message on Discord for better UX.

Does your solution involve any of the following?

Describe alternatives you've considered

Assigning the Administrator permission to the bot should prevent the permission error but our official guide states that it's optional, and it's generally considered good security practice to not assign Admin permission to a bot.

Who will this benefit?

This will benefit users who would like to fine-tune the permissions for the bot to only have what the bot really needs.

Additional Information

No response