Closed charlie-moomoo closed 1 year ago
How about more exception handlers? Such as command not found, error while processing commands / events… etc.
I wish I could do something like this:
def error():
print('oh no')
class MyCog(Client.Commands, prefix="!"):
@cmd(name="hi",on_error=error)
def hi(ctx):
ctx.reply('hi')
Generally, if there are too many errors to handle, it might cause you to create too many functions OUTSIDE the cog. I think using an event handler would be the best:
class Cog(Client.Commands, ...):
@cmd(name=...)
def fn(ctx):
...
@fn.error()
def on_error(ctx, error):
ctx.reply(
"I know you hate errors" if isinstance(error, BadArguments) else "ok idk what error"
)
Oh, that looks good. :)
And rename cmd
to command
please,.
Hey, @charlie-moomoo. Thanks for the advice, I've added it to Linelib, you can now access it with the following script:
cmd = Client.Commands.cmd
class foo(Client.Commands):
@cmd(...)
def bar(ctx, arg1: str):
pass
@bar.error()
def onError(ctx, error):
ctx.reply("Please pass in arguments properly.")
Additionally, I'd like to provide you more detailed info about the triggering.
The @bar.error()
script will be triggered when the following occurrs:
str
to the requested typerequested type: You can assign them inside your functions:
func(ctx, foo: str, bar: int)
linelib will auto-convert them into specified types.
However, the Client.command
method will remain unchanged until further notice.
Cheers! AWeirdDev
@sus2790: And rename
cmd
tocommand
please,.
Hey there!
As @charlie-moomoo referenced in their issue, the cmd
variable is pointed directly to Client.Commands.cmd
(an alias of Client.Commands.command
.
If you want to create a basic command, use the following instead:
@client.command
Thanks!
Currently, if the command is missing an argument, it will occur following error:
We should be able to handle the error, so we can warn the user give all arguments.