Przeglądaj źródła

Add examples for creating bot account

Bruce Marriner 8 lat temu
rodzic
commit
1cc1d4c9bb
1 zmienionych plików z 34 dodań i 0 usunięć
  1. 34 0
      oauth2_test.go

+ 34 - 0
oauth2_test.go

@@ -38,6 +38,10 @@ func ExampleApplication() {
 	ap, err = dg.ApplicationUpdate(ap.ID, ap)
 	fmt.Printf("ApplicationUpdate: err: %+v, app: %+v\n", err, ap)
 
+	// create a new bot account for this application
+	bot, err := dg.ApplicationBotCreate(ap.ID, "")
+	fmt.Printf("BotCreate: err: %+v, bot: %+v\n", err, bot)
+
 	// Get a list of all applications for the authenticated user
 	apps, err := dg.Applications()
 	fmt.Printf("Applications: err: %+v, apps : %+v\n", err, apps)
@@ -51,3 +55,33 @@ func ExampleApplication() {
 
 	return
 }
+
+// This provides an example on converting an existing normal user account
+// into a bot account.  You must authentication to Discord using your personal
+// username and password then provide the authentication token of the account
+// you want converted.
+func ExampleApplicationConvertBot() {
+
+	dg, err := discordgo.New("myemail", "mypassword")
+	if err != nil {
+		fmt.Println(err)
+		return
+	}
+
+	// create an application
+	ap := &discordgo.Application{}
+	ap.Name = "Application Name"
+	ap.Description = "Application Description"
+	ap, err = dg.ApplicationCreate(ap)
+	fmt.Printf("ApplicationCreate: err: %+v, app: %+v\n", err, ap)
+
+	// create a bot account
+	bot, err := dg.ApplicationBotCreate(ap.ID, "existing bot user account token")
+	fmt.Printf("BotCreate: err: %+v, bot: %+v\n", err, bot)
+
+	if err != nil {
+		fmt.Printf("You can not login with your converted bot user using the below token\n%s\n", bot.Token)
+	}
+
+	return
+}