Added ApplicationBotCreate function

This commit is contained in:
Bruce Marriner 2016-03-11 15:58:38 -06:00
parent f4f68879ab
commit 24be2cda0b
2 changed files with 36 additions and 4 deletions

View file

@ -86,7 +86,8 @@ var (
EMOJI = func(eID string) string { return API + "emojis/" + eID + ".png" }
OAUTH2 = API + "oauth2/"
APPLICATIONS = OAUTH2 + "applications"
APPLICATION = func(aID string) string { return APPLICATIONS + "/" + aID }
OAUTH2 = API + "oauth2/"
APPLICATIONS = OAUTH2 + "applications"
APPLICATION = func(aID string) string { return APPLICATIONS + "/" + aID }
APPLICATIONS_BOT = func(aID string) string { return APPLICATIONS + "/" + aID + "/bot" }
)

View file

@ -5,7 +5,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// This file contains functions related to Discord OAuth2 applications
// This file contains functions related to Discord OAuth2 endpoints
package discordgo
@ -13,6 +13,10 @@ import (
"fmt"
)
// ------------------------------------------------------------------------------------------------
// Code specific to Discord OAuth2 Applications
// ------------------------------------------------------------------------------------------------
// An Application struct stores values for a Discord OAuth2 Application
type Application struct {
ID string `json:"id,omitempty"`
@ -132,3 +136,30 @@ func (a *Application) Delete() (err error) {
func (a *Application) DeleteB(s *Session) (err error) {
return s.ApplicationDelete(a.ID)
}
// ------------------------------------------------------------------------------------------------
// Code specific to Discord OAuth2 Application Bots
// ------------------------------------------------------------------------------------------------
// ApplicationBotCreate creates an Application Bot Account
//
// appID : The ID of an Application
// token : The authentication Token for a user account to convert into
// a bot account. This is optional, if omited a new account
// is created using the name of the application.
//
// NOTE: func name may change, if I can think up something better.
func (s *Session) ApplicationBotCreate(appID, token string) (st *User, err error) {
data := struct {
Token string `json:"token,omitempty"`
}{token}
body, err := s.Request("POST", APPLICATIONS_BOT(appID), data)
if err != nil {
return
}
err = unmarshal(body, &st)
return
}