Exemplo n.º 1
0
    async def reinvoke(self, ctx: commands.Context, *, call_hooks=False):
        early_invoke = not self.invoke_without_command
        if early_invoke:
            ctx.command = self
            await self._parse_arguments(ctx)

            if call_hooks:
                await self.call_before_hooks(ctx)

        view = ctx.view
        previous = view.index
        view.skip_ws()
        trigger = view.get_word()

        if trigger:
            ctx.subcommand_passed = trigger
            ctx.invoked_subcommand = self.all_commands.get(trigger)

        if early_invoke:
            try:
                await self.callback(*ctx.args, **ctx.kwargs)
            except Exception:
                ctx.command_failed = True
                raise
            finally:
                if call_hooks:
                    await self.call_after_hooks(ctx)

        if trigger and ctx.invoked_subcommand:
            ctx.invoked_with = trigger
            await ctx.invoked_subcommand.reinvoke(ctx, call_hooks=call_hooks)
        elif not early_invoke:
            view.index = previous
            view.previous = previous
            await super().reinvoke(ctx, call_hooks=call_hooks)
Exemplo n.º 2
0
    async def newrc_error(self, ctx: commands.Context,
                          error: commands.CommandError) -> None:
        """Error handler for newrr command.
        If valid argument were not given, send feedback to user.

        Parameters
        ------------
        ctx: `commands.Context`
            A class containing metadata about the command invocation.
        error `commands.CommandError`:
            The error which was raised.
        """

        if isinstance(error, commands.BadArgument):
            if isinstance(error.__cause__, ValueError):
                await ctx.send(
                    f"`message_id: {ctx.args.message_id}` is not a valid integer."
                )
            else:
                await ctx.send(error)
            ctx.command_failed = False