mirror of
https://github.com/diamondburned/arikawa.git
synced 2025-01-21 03:57:26 +00:00
Bot: Add ErrorReplier
This commit adds the ErrorReplier callback into Context, which allows the user to implement a custom way to format errors, such as putting them into an embed.
This commit is contained in:
parent
728bc5c472
commit
cafff103e5
|
@ -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.
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue