added create invite function.
This commit is contained in:
parent
c157bb6028
commit
68e7355db8
22
channel.go
22
channel.go
@ -180,3 +180,25 @@ func (c Channel) Delete() error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create a new invite.
|
||||||
|
// Returns a string (invite code) and error (nil if not exists).
|
||||||
|
func (c Channel) CreateInvite() (string, error) {
|
||||||
|
data, err := c.Client.Request("POST", "/channels/"+c.Id+"/invites", []byte{})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
dataStruct := &struct {
|
||||||
|
InviteCode string `json:"code"`
|
||||||
|
}{}
|
||||||
|
|
||||||
|
err = json.Unmarshal(data, dataStruct)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return dataStruct.InviteCode, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return dataStruct.InviteCode, nil
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user