oauth2_test.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package discordgo_test
  2. import (
  3. "fmt"
  4. "os"
  5. "github.com/bwmarrin/discordgo"
  6. )
  7. func ExampleApplication() {
  8. // Authentication Token pulled from environment variable DG_TOKEN
  9. Token := os.Getenv("DG_TOKEN")
  10. if Token == "" {
  11. return
  12. }
  13. // Create a new Discordgo session
  14. dg, err := discordgo.New(Token)
  15. if err != nil {
  16. fmt.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. fmt.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. fmt.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. fmt.Printf("ApplicationUpdate: err: %+v, app: %+v\n", err, ap)
  32. // Get a list of all applications for the authenticated user
  33. apps, err := dg.Applications()
  34. fmt.Printf("Applications: err: %+v, apps : %+v\n", err, apps)
  35. for k, v := range apps {
  36. fmt.Printf("Applications: %d : %+v\n", k, v)
  37. }
  38. // Delete the application we created.
  39. err = ap.Delete()
  40. fmt.Printf("Delete: err: %+v\n", err)
  41. return
  42. }