main.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. dg, err := discordgo.New(Email, Password, Token)
  23. if err != nil {
  24. fmt.Println("error creating Discord session,", err)
  25. return
  26. }
  27. // Register messageCreate as a callback for the messageCreate events.
  28. dg.AddHandler(messageCreate)
  29. // Open the websocket and begin listening.
  30. dg.Open()
  31. fmt.Println("Bot is now running. Press CTRL-C to exit.")
  32. // Simple way to keep program running until CTRL-C is pressed.
  33. <-make(chan struct{})
  34. return
  35. }
  36. // This function will be called (due to AddHandler above) every time a new
  37. // message is created on any channel that the autenticated bot has access to.
  38. func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
  39. // Print message to stdout.
  40. fmt.Printf("%20s %20s %20s > %s\n", m.ChannelID, time.Now().Format(time.Stamp), m.Author.Username, m.Content)
  41. }