forked from NdoleStudio/httpsms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapplication_service.go
More file actions
34 lines (28 loc) · 992 Bytes
/
Copy pathapplication_service.go
File metadata and controls
34 lines (28 loc) · 992 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package discord
import (
"context"
"encoding/json"
"fmt"
"net/http"
)
// ApplicationService is the API client for the interacting with commands
type ApplicationService service
// CreateCommand creates a new guild command
//
// API Docs: https://discord.com/developers/docs/interactions/application-commands#create-guild-application-command
func (service *ApplicationService) CreateCommand(ctx context.Context, serverID string, params *CommandCreateRequest) (*CommandCreateResponse, *Response, error) {
url := fmt.Sprintf("/applications/%s/guilds/%s/commands", service.client.applicationID, serverID)
request, err := service.client.newRequest(ctx, http.MethodPost, url, params)
if err != nil {
return nil, nil, err
}
response, err := service.client.do(request)
if err != nil {
return nil, response, err
}
message := new(CommandCreateResponse)
if err = json.Unmarshal(*response.Body, message); err != nil {
return nil, response, err
}
return message, response, nil
}