mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 03:08:55 -05:00
Core - Add invoke error message customisation (#5894)
Co-authored-by: Jakub Kuczys <me@jacken.men>
This commit is contained in:
parent
88a348210c
commit
60a9d47003
@ -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:
|
||||
|
||||
"""""""""
|
||||
|
||||
@ -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):
|
||||
|
||||
@ -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],
|
||||
|
||||
@ -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):
|
||||
|
||||
@ -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(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user