Skip to content

Instantly share code, notes, and snippets.

@jaydonnell
Created October 5, 2020 02:57
Show Gist options
  • Save jaydonnell/d7586591001d5adaaa58f30d9a6388e8 to your computer and use it in GitHub Desktop.
Save jaydonnell/d7586591001d5adaaa58f30d9a6388e8 to your computer and use it in GitHub Desktop.
package main
import (
"context"
"fmt"
"strings"
"github.com/andersfylling/disgord"
)
func printMessage(session disgord.Session, evt *disgord.MessageCreate) {
fmt.Println(evt.Message.Author, " said:")
fmt.Println(evt.Message.Content)
fmt.Println(evt.Message.Author.ID)
fmt.Println()
if strings.Contains(evt.Message.Content, "ping") && !evt.Message.Author.Bot {
//_, _ = evt.Message.Reply(context.Background(), session, "pong")
_, _, _ = evt.Message.Author.SendMsgString(evt.Ctx, session, "dm pong")
}
}
func sendDM(session disgord.Session, evt *disgord.MessageCreate) {
fmt.Println(evt)
}
func main() {
client := disgord.New(disgord.Config{
BotToken: "<token goes here>",
})
// connect, and stay connected until a system interrupt takes place
defer client.StayConnectedUntilInterrupted(context.Background())
// create a handler and bind it to new message events
// handlers/listener are run in sequence if you register more than one
// so you should not need to worry about locking your objects unless you do any
// parallel computing with said objects
client.On(disgord.EvtMessageCreate, printMessage)
client.On(disgord.EvtTypingStart, sendDM)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment