From 3ad90eddbf72ef323a57595fc8dca3171bd26261 Mon Sep 17 00:00:00 2001 From: Sebastian Cabrera Date: Tue, 16 Jan 2024 16:58:02 -0500 Subject: [PATCH] Minor refactor --- callbacks.go | 1 + main.go | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/callbacks.go b/callbacks.go index 111eb35..d3c5bb2 100644 --- a/callbacks.go +++ b/callbacks.go @@ -13,6 +13,7 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) { if m.Author.ID == s.State.User.ID { return } + // If the message is "ping" reply with "Pong!" if m.Content == "ping" { s.ChannelMessageSend(m.ChannelID, "Pong!") diff --git a/main.go b/main.go index a878280..02f5229 100644 --- a/main.go +++ b/main.go @@ -25,20 +25,20 @@ func init() { func main() { // Create a new Discord session using the provided bot token. - dg, err := discordgo.New("Bot " + token) + bot, err := discordgo.New("Bot " + token) if err != nil { fmt.Println("Error creating Discord session,", err) return } // Register the messageCreate func as a callback for MessageCreate events. - dg.AddHandler(messageCreate) + bot.AddHandler(messageCreate) // In this example, we only care about receiving message events. - dg.Identify.Intents = discordgo.IntentsGuildMessages + bot.Identify.Intents = discordgo.IntentsGuildMessages // Open a websocket connection to Discord and begin listening. - err = dg.Open() + err = bot.Open() if err != nil { fmt.Println("Error opening connection,", err) return @@ -51,5 +51,5 @@ func main() { <-sc // Cleanly close down the Discord session. - dg.Close() + bot.Close() }