From 16861ec98cc116812fd76f819c0e2d397b6714d4 Mon Sep 17 00:00:00 2001 From: Xevion Date: Tue, 19 Dec 2023 08:03:46 -0600 Subject: [PATCH] Error handling helper for interactions --- helpers.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/helpers.go b/helpers.go index b07b0e1..cf48a77 100644 --- a/helpers.go +++ b/helpers.go @@ -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) + } +}