mirror of
https://github.com/Xevion/r2park.git
synced 2026-01-31 04:25:23 -06:00
Error handling helper for interactions
This commit is contained in:
+26
@@ -10,6 +10,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@@ -168,3 +169,28 @@ func GetFooterText() string {
|
||||
time.Now().Format("Jan 2, 2006 3:04:05PM"),
|
||||
strings.ToLower(CommitId[:7]))
|
||||
}
|
||||
|
||||
// HandleError(session, interaction, parse_err)
|
||||
func HandleError(session *discordgo.Session, interaction *discordgo.InteractionCreate, err error, message string) {
|
||||
if err != nil {
|
||||
log.Errorf("%s (%v)", message, err)
|
||||
}
|
||||
|
||||
err = session.InteractionRespond(interaction.Interaction, &discordgo.InteractionResponse{
|
||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||
Data: &discordgo.InteractionResponseData{
|
||||
Embeds: []*discordgo.MessageEmbed{
|
||||
{
|
||||
Footer: &discordgo.MessageEmbedFooter{
|
||||
Text: GetFooterText(),
|
||||
},
|
||||
Description: message,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
log.Warn("Unable to provide error response to user.", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user