Skip to content

Commit

Permalink
add a basic discord bot impl
Browse files Browse the repository at this point in the history
  • Loading branch information
jrhackett committed Sep 20, 2018
1 parent ef9eba3 commit 7a3671b
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
6 changes: 6 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
module github.com/shots-fired/shots-discord

require (
github.com/bwmarrin/discordgo v0.18.0
github.com/gorilla/websocket v1.4.0 // indirect
golang.org/x/crypto v0.0.0-20180910181607-0e37d006457b // indirect
)
49 changes: 49 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,54 @@
package main

import (
"fmt"
"os"

"github.com/bwmarrin/discordgo"
)

var botID string

const commandPrefix string = "!"

func main() {
discord, err := discordgo.New("Bot " + os.Getenv("BOT_KEY"))
if err != nil {
panic(err)
}

user, err := discord.User("@me")
if err != nil {
panic(err)
}

botID = user.ID

discord.AddHandler(commandHandler)

discord.AddHandler(func(discord *discordgo.Session, ready *discordgo.Ready) {
err = discord.UpdateStatus(0, "I am Shots! Hear me roar!")
if err != nil {
fmt.Println("Error attempting to set my status")
}
fmt.Printf("Shots has started on %d servers", len(discord.State.Guilds))
})

err = discord.Open()
if err != nil {
panic(err)
}
defer discord.Close()

<-make(chan struct{})
}

func commandHandler(discord *discordgo.Session, message *discordgo.MessageCreate) {
user := message.Author
if user.ID == botID || user.Bot {
//Do nothing because the bot is talking
return
}

fmt.Printf("Message: %+v || From: %s\n", message.Message, message.Author)
}

0 comments on commit 7a3671b

Please sign in to comment.