main.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. "github.com/bwmarrin/discordgo"
  6. )
  7. var (
  8. Email string
  9. Password string
  10. Token string
  11. AppName string
  12. ConvToken string
  13. DeleteID string
  14. ListOnly bool
  15. )
  16. func init() {
  17. flag.StringVar(&Email, "e", "", "Account Email")
  18. flag.StringVar(&Password, "p", "", "Account Password")
  19. flag.StringVar(&Token, "t", "", "Account Token")
  20. flag.StringVar(&DeleteID, "d", "", "Application ID to delete")
  21. flag.BoolVar(&ListOnly, "l", false, "List Applications Only")
  22. flag.StringVar(&AppName, "a", "", "App/Bot Name")
  23. flag.Parse()
  24. }
  25. func main() {
  26. // Create a new Discord session using the provided login information.
  27. dg, err := discordgo.New(Email, Password, Token)
  28. if err != nil {
  29. fmt.Println("error creating Discord session,", err)
  30. return
  31. }
  32. // If -l set, only display a list of existing applications
  33. // for the given account.
  34. if ListOnly {
  35. aps, err := dg.Applications()
  36. if err != nil {
  37. fmt.Println("error fetching applications,", err)
  38. return
  39. }
  40. for k, v := range aps {
  41. fmt.Printf("%d : --------------------------------------\n", k)
  42. fmt.Printf("ID: %s\n", v.ID)
  43. fmt.Printf("Name: %s\n", v.Name)
  44. fmt.Printf("Secret: %s\n", v.Secret)
  45. fmt.Printf("Description: %s\n", v.Description)
  46. }
  47. return
  48. }
  49. // if -d set, delete the given Application
  50. if DeleteID != "" {
  51. err := dg.ApplicationDelete(DeleteID)
  52. if err != nil {
  53. fmt.Println("error deleting application,", err)
  54. }
  55. return
  56. }
  57. // Create a new application.
  58. ap := &discordgo.Application{}
  59. ap.Name = AppName
  60. ap, err = dg.ApplicationCreate(ap)
  61. if err != nil {
  62. fmt.Println("error creating new applicaiton,", err)
  63. return
  64. }
  65. fmt.Printf("Application created successfully:\n")
  66. fmt.Printf("ID: %s\n", ap.ID)
  67. fmt.Printf("Name: %s\n", ap.Name)
  68. fmt.Printf("Secret: %s\n\n", ap.Secret)
  69. // Create the bot account under the application we just created
  70. bot, err := dg.ApplicationBotCreate(ap.ID)
  71. if err != nil {
  72. fmt.Println("error creating bot account,", err)
  73. return
  74. }
  75. fmt.Printf("Bot account created successfully.\n")
  76. fmt.Printf("ID: %s\n", bot.ID)
  77. fmt.Printf("Username: %s\n", bot.Username)
  78. fmt.Printf("Token: %s\n\n", bot.Token)
  79. fmt.Println("Please save the above posted info in a secure place.")
  80. fmt.Println("You will need that information to login with your bot account.")
  81. return
  82. }