main.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. "time"
  6. "github.com/bwmarrin/discordgo"
  7. )
  8. var (
  9. Email string
  10. Password string
  11. Token string
  12. BotID string
  13. )
  14. func init() {
  15. flag.StringVar(&Email, "e", "", "Account Email")
  16. flag.StringVar(&Password, "p", "", "Account Password")
  17. flag.StringVar(&Token, "t", "", "Account Token")
  18. flag.Parse()
  19. }
  20. func main() {
  21. // Create a new Discord session using the provided login information.
  22. // Use discordgo.New(Token) to just use a token for login.
  23. dg, err := discordgo.New(Email, Password, Token)
  24. if err != nil {
  25. fmt.Println("error creating Discord session,", err)
  26. return
  27. }
  28. // Register messageCreate as a callback for the messageCreate events.
  29. dg.AddHandler(messageCreate)
  30. // Open the websocket and begin listening.
  31. dg.Open()
  32. fmt.Println("Bot is now running. Press CTRL-C to exit.")
  33. // Simple way to keep program running until CTRL-C is pressed.
  34. <-make(chan struct{})
  35. return
  36. }
  37. // This function will be called (due to AddHandler above) every time a new
  38. // message is created on any channel that the autenticated bot has access to.
  39. func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
  40. // Print message to stdout.
  41. fmt.Printf("%20s %20s %20s > %s\n", m.ChannelID, time.Now().Format(time.Stamp), m.Author.Username, m.Content)
  42. }