oauth2_test.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package discordgo_test
  2. import (
  3. "log"
  4. "os"
  5. "github.com/bwmarrin/discordgo"
  6. )
  7. func ExampleApplication() {
  8. // Authentication Token pulled from environment variable DGU_TOKEN
  9. Token := os.Getenv("DGU_TOKEN")
  10. if Token == "" {
  11. return
  12. }
  13. // Create a new Discordgo session
  14. dg, err := discordgo.New(Token)
  15. if err != nil {
  16. log.Println(err)
  17. return
  18. }
  19. // Create an new Application
  20. ap := &discordgo.Application{}
  21. ap.Name = "TestApp"
  22. ap.Description = "TestDesc"
  23. ap, err = dg.ApplicationCreate(ap)
  24. log.Printf("ApplicationCreate: err: %+v, app: %+v\n", err, ap)
  25. // Get a specific Application by it's ID
  26. ap, err = dg.Application(ap.ID)
  27. log.Printf("Application: err: %+v, app: %+v\n", err, ap)
  28. // Update an existing Application with new values
  29. ap.Description = "Whooooa"
  30. ap, err = dg.ApplicationUpdate(ap.ID, ap)
  31. log.Printf("ApplicationUpdate: err: %+v, app: %+v\n", err, ap)
  32. // create a new bot account for this application
  33. bot, err := dg.ApplicationBotCreate(ap.ID)
  34. log.Printf("BotCreate: err: %+v, bot: %+v\n", err, bot)
  35. // Get a list of all applications for the authenticated user
  36. apps, err := dg.Applications()
  37. log.Printf("Applications: err: %+v, apps : %+v\n", err, apps)
  38. for k, v := range apps {
  39. log.Printf("Applications: %d : %+v\n", k, v)
  40. }
  41. // Delete the application we created.
  42. err = dg.ApplicationDelete(ap.ID)
  43. log.Printf("Delete: err: %+v\n", err)
  44. return
  45. }