|
@@ -27,9 +27,10 @@ func main() {
|
|
var err error
|
|
var err error
|
|
|
|
|
|
// Create a new Discord Session and set a handler for the OnMessageCreate
|
|
// Create a new Discord Session and set a handler for the OnMessageCreate
|
|
- // event that happens for every new message on any channel
|
|
|
|
|
|
+ // event that happens for every new message on any channel
|
|
Session := discordgo.Session{
|
|
Session := discordgo.Session{
|
|
OnMessageCreate: messageCreate,
|
|
OnMessageCreate: messageCreate,
|
|
|
|
+ OnReady: ready,
|
|
}
|
|
}
|
|
|
|
|
|
// Login to the Discord server and store the authentication token
|
|
// Login to the Discord server and store the authentication token
|
|
@@ -57,6 +58,12 @@ func main() {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func ready(s *discordgo.Session, r discordgo.Ready) {
|
|
|
|
+ // start the Heartbeat. This is required
|
|
|
|
+ // to keep the websocket connection open
|
|
|
|
+ go s.Heartbeat(r.HeartbeatInterval)
|
|
|
|
+}
|
|
|
|
+
|
|
func messageCreate(s *discordgo.Session, m discordgo.Message) {
|
|
func messageCreate(s *discordgo.Session, m discordgo.Message) {
|
|
fmt.Printf("%25d %s %20s > %s\n", m.ChannelID, time.Now().Format(time.Stamp), m.Author.Username, m.Content)
|
|
fmt.Printf("%25d %s %20s > %s\n", m.ChannelID, time.Now().Format(time.Stamp), m.Author.Username, m.Content)
|
|
}
|
|
}
|