File size: 992 Bytes
83a59ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
35
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
}