diff --git a/bot/ctx.go b/bot/ctx.go index 864983e..07cdbb1 100644 --- a/bot/ctx.go +++ b/bot/ctx.go @@ -127,6 +127,15 @@ type Context struct { // MessageCreate events. ReplyError bool + // ErrorReplier is an optional function that allows changing how the error + // is replied. It overrides ReplyError and is only used for MessageCreate + // events. + // + // Note that errors that are passed in here will bypas FormatError; in other + // words, the implementation might only care about ErrorReplier and leave + // FormatError as it is. + ErrorReplier func(err error, src *gateway.MessageCreateEvent) api.SendMessageData + // EditableCommands when true will also listen for MessageUpdateEvent and // treat them as newly created messages. This is convenient if you want // to quickly edit a message and re-execute the command. diff --git a/bot/ctx_call.go b/bot/ctx_call.go index 4519154..20b129a 100644 --- a/bot/ctx_call.go +++ b/bot/ctx_call.go @@ -114,14 +114,18 @@ func (ctx *Context) callMessageCreate( return nil } - if err != nil && !ctx.ReplyError { + if err != nil && !ctx.ReplyError && ctx.ErrorReplier == nil { return err } var data api.SendMessageData if err != nil { - data.Content = ctx.FormatError(err) + if ctx.ErrorReplier != nil { + data = ctx.ErrorReplier(err, mc) + } else { + data.Content = ctx.FormatError(err) + } } else { switch v := v.(type) { case string: