Minor refactor
This commit is contained in:
parent
ba31086469
commit
3ad90eddbf
2 changed files with 6 additions and 5 deletions
|
@ -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!")
|
||||
|
|
10
main.go
10
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()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue