From 9d5164be657a1192c705a53c94fb8fa74610b858 Mon Sep 17 00:00:00 2001 From: "diamondburned (Forefront)" Date: Sat, 25 Jan 2020 14:15:42 -0800 Subject: [PATCH] Fixed subcommand bug where argv[0] is invalid --- bot/ctx_call.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/bot/ctx_call.go b/bot/ctx_call.go index d1c28a8..f01a775 100644 --- a/bot/ctx_call.go +++ b/bot/ctx_call.go @@ -224,21 +224,24 @@ func (ctx *Context) callMessageCreate(mc *gateway.MessageCreateEvent) error { } } - // Create a zero value instance of this + // Create a zero value instance of this: v := reflect.New(cmd.Arguments[0].Type) - // Call the manual parse method + // Pop out the subcommand name: + args = args[1:] + + // Call the manual parse method: ret := cmd.Arguments[0].manual.Func.Call([]reflect.Value{ v, reflect.ValueOf(args), }) - // Check the method returns for error + // Check the method returns for error: if err := errorReturns(ret); err != nil { // TODO: maybe wrap this? return err } - // Add the pointer to the argument into argv + // Add the pointer to the argument into argv: argv = append(argv, v) goto Call }