--- a/main.go Wed Mar 20 03:49:43 2019 +0000
+++ b/main.go Tue Mar 19 21:40:24 2019 -0700
@@ -8,17 +8,20 @@
"github.com/bwmarrin/discordgo"
logger = log.New(os.Stderr, " ", log.Ldate|log.Ltime)
flag.StringVar(&Token, "t", "", "Bot Token")
@@ -34,6 +37,11 @@
+func logError(v ...interface{}) { + logger.SetPrefix("ERROR ") logDebug("Bot Token:", Token)
@@ -71,18 +79,26 @@
func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
logDebug("Message: ", m.Content)
- // Ignore all messages created by the bot itself
- // This isn't required in this specific example but it's a good practice.
if m.Author.ID == s.State.User.ID {
- // If the message is "ping" reply with "Pong!"
- if m.Content == "ping" {
- s.ChannelMessageSend(m.ChannelID, "Pong!")
- // If the message is "pong" reply with "Ping!"
- if m.Content == "pong" {
- s.ChannelMessageSend(m.ChannelID, "Ping!")
+ if strings.EqualFold(m.Content, "!uptime") { + duration := time.Now().Sub(startTime) + err := sendMessage(s, m.ChannelID, fmt.Sprintf( + "Uptime is: **%02d:%02d:%02d** (since **%s**)", + int(duration.Minutes())%60, + int(duration.Seconds())%60, + startTime.Format(time.Stamp))) +func sendMessage(sess *discordgo.Session, channelid, message string) error { + logInfo("SENDING MESSAGE:", message) + _, err := sess.ChannelMessageSend(channelid, message)