diff --git a/docs/cog_guides/core.rst b/docs/cog_guides/core.rst index 2e99181f8..be1b76ad8 100644 --- a/docs/cog_guides/core.rst +++ b/docs/cog_guides/core.rst @@ -3080,6 +3080,35 @@ This is only applied to the current server and not globally. **Arguments:** - ``[time]`` - The seconds to wait before deleting the command message. Use -1 to disable. +.. _core-command-set-errormsg: + +"""""""""""" +set errormsg +"""""""""""" + +.. note:: |owner-lock| + +**Syntax** + +.. code-block:: none + + [p]set errormsg [msg] + +**Description** + +Set the message that will be sent on uncaught bot errors. + +To include the command name in the message, use the ``{command}`` placeholder. + +If you omit the ``msg`` argument, the message will be reset to the default one. + +**Examples:** + - ``[p]set errormsg`` - Resets the error message back to the default: "Error in command '{command}'.". If the command invoker is one of the bot owners, the message will also include "Check your console or logs for details.". + - ``[p]set errormsg Oops, the command {command} has failed! Please try again later.`` - Sets the error message to a custom one. + +**Arguments:** + - ``[msg]`` - The custom error message. Must be less than 1000 characters. Omit to reset to the default one. + .. _core-command-set-fuzzy: """"""""" diff --git a/redbot/cogs/trivia/session.py b/redbot/cogs/trivia/session.py index 7c8f873c4..6c5770a1f 100644 --- a/redbot/cogs/trivia/session.py +++ b/redbot/cogs/trivia/session.py @@ -118,13 +118,12 @@ class TriviaSession: self.stop() except Exception as exc: LOG.error("A trivia session has encountered an error.\n", exc_info=exc) - asyncio.create_task( - self.ctx.send( - _( - "An unexpected error occurred in the trivia session.\nCheck your console or logs for details." - ) + msg = _("An unexpected error occurred in the trivia session.") + if self.ctx.author.id in self.ctx.bot.owner_ids: + msg = _( + "An unexpected error occurred in the trivia session.\nCheck your console or logs for details." ) - ) + asyncio.create_task(self.ctx.send(msg)) self.stop() async def run(self): diff --git a/redbot/core/bot.py b/redbot/core/bot.py index 7e58375c0..06e784664 100644 --- a/redbot/core/bot.py +++ b/redbot/core/bot.py @@ -134,6 +134,7 @@ class Red( invite_commands_scope=False, disabled_commands=[], disabled_command_msg="That command is disabled.", + invoke_error_msg=None, extra_owner_destinations=[], owner_opt_out_list=[], last_system_info__python_version=[3, 7], diff --git a/redbot/core/core_commands.py b/redbot/core/core_commands.py index 0593afed8..26ec04e75 100644 --- a/redbot/core/core_commands.py +++ b/redbot/core/core_commands.py @@ -3646,7 +3646,7 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic): @_set.command(name="usebuttons") @checks.is_owner() - async def use_buttons(self, ctx: commands.Context, use_buttons: bool = None): + async def _set_usebuttons(self, ctx: commands.Context, use_buttons: bool = None): """ Set a global bot variable for using buttons in menus. @@ -3655,7 +3655,7 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic): This defaults to False. Using this without a setting will toggle. - **Examples:** + **Examples:** - `[p]set usebuttons True` - Enables using buttons. - `[p]helpset usebuttons` - Toggles the value. @@ -3670,6 +3670,35 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic): else: await ctx.send(_("I will not use buttons on basic menus.")) + @_set.command(name="errormsg") + @commands.is_owner() + async def _set_errormsg(self, ctx: commands.Context, *, msg: str = None): + """ + Set the message that will be sent on uncaught bot errors. + + To include the command name in the message, use the `{command}` placeholder. + + If you omit the `msg` argument, the message will be reset to the default one. + + **Examples:** + - `[p]set errormsg` - Resets the error message back to the default: "Error in command '{command}'.". If the command invoker is one of the bot owners, the message will also include "Check your console or logs for details.". + - `[p]set errormsg Oops, the command {command} has failed! Please try again later.` - Sets the error message to a custom one. + + **Arguments:** + - `[msg]` - The custom error message. Must be less than 1000 characters. Omit to reset to the default one. + """ + if msg is not None and len(msg) >= 1000: + return await ctx.send(_("The message must be less than 1000 characters.")) + + if msg is not None: + await self.bot._config.invoke_error_msg.set(msg) + content = _("Succesfully updated the error message.") + else: + await self.bot._config.invoke_error_msg.clear() + content = _("Successfully reset the error message back to the default one.") + + await ctx.send(content) + @commands.group() @checks.is_owner() async def helpset(self, ctx: commands.Context): diff --git a/redbot/core/events.py b/redbot/core/events.py index 3811f38be..d1651eadf 100644 --- a/redbot/core/events.py +++ b/redbot/core/events.py @@ -266,16 +266,21 @@ def init_events(bot, cli_flags): "Exception in command '{}'".format(ctx.command.qualified_name), exc_info=error.original, ) - - message = _( - "Error in command '{command}'. Check your console or logs for details." - ).format(command=ctx.command.qualified_name) exception_log = "Exception in command '{}'\n" "".format(ctx.command.qualified_name) exception_log += "".join( traceback.format_exception(type(error), error, error.__traceback__) ) bot._last_exception = exception_log - await ctx.send(inline(message)) + + message = await bot._config.invoke_error_msg() + if not message: + if ctx.author.id in bot.owner_ids: + message = inline( + _("Error in command '{command}'. Check your console or logs for details.") + ) + else: + message = inline(_("Error in command '{command}'.")) + await ctx.send(message.replace("{command}", ctx.command.qualified_name)) elif isinstance(error, commands.CommandNotFound): help_settings = await HelpSettings.from_context(ctx) fuzzy_commands = await fuzzy_command_search(