@@ -63,29 +63,46 @@ type GuildApplicationCommandPermissions struct {
6363}
6464
6565type ApplicationCommand struct {
66- ID Snowflake `json:"id"`
67- Type ApplicationCommandType `json:"type"`
68- ApplicationID Snowflake `json:"application_id"`
69- GuildID Snowflake `json:"guild_id"`
70- Name string `json:"name"`
71- Description string `json:"description"`
72- Options []* ApplicationCommandOption `json:"options"`
73- DefaultPermission bool `json:"default_permission,omitempty"`
66+ ID Snowflake `json:"id"`
67+ Type ApplicationCommandType `json:"type,omitempty"`
68+ ApplicationID Snowflake `json:"application_id"`
69+ GuildID Snowflake `json:"guild_id,omitempty"`
70+ Name string `json:"name"`
71+ NameLocalizations map [string ]string `json:"name_localization,omitempty"`
72+ Description string `json:"description"`
73+ DescriptionLocalizations map [string ]string `json:"description_localization,omitempty"`
74+ Options []* ApplicationCommandOption `json:"options,omitempty"`
75+ DefaultMemberPermissions * PermissionBit `json:"default_member_permissions,omitempty"`
76+ DMPermission * bool `json:"dm_permission,omitempty"` // Global only.
77+ DefaultPermission bool `json:"default_permission,omitempty"`
78+ NSFW bool `json:"nsfw,omitempty"`
79+ Version Snowflake `json:"version,omitempty"`
7480}
7581
7682type CreateApplicationCommand struct {
77- Name string `json:"name"`
78- Description string `json:"description"`
79- Type ApplicationCommandType `json:"type,omitempty"`
80- Options []* ApplicationCommandOption `json:"options,omitempty"`
81- DefaultPermission bool `json:"default_permission,omitempty"`
83+ Name string `json:"name"`
84+ NameLocalizations map [string ]string `json:"name_localization,omitempty"`
85+ Description string `json:"description,omitempty"`
86+ DescriptionLocalizations map [string ]string `json:"description_localization,omitempty"`
87+ Type ApplicationCommandType `json:"type,omitempty"`
88+ Options []* ApplicationCommandOption `json:"options,omitempty"`
89+ DMPermission * bool `json:"dm_permission,omitempty"`
90+ DefaultMemberPermissions * PermissionBit `json:"default_member_permissions,omitempty"`
91+ DefaultPermission bool `json:"default_permission,omitempty"`
92+ NSFW * bool `json:"nsfw,omitempty"`
8293}
8394
8495type UpdateApplicationCommand struct {
85- Name * string `json:"name,omitempty"`
86- DefaultPermission * bool `json:"default_permission,omitempty"`
87- Description * string `json:"description,omitempty"`
88- Options * []* ApplicationCommandOption `json:"options,omitempty"`
96+ Name * string `json:"name,omitempty"`
97+ NameLocalizations * map [string ]string `json:"name_localization,omitempty"`
98+ Description * string `json:"description,omitempty"`
99+ DescriptionLocalizations * map [string ]string `json:"description_localization,omitempty"`
100+ Type * ApplicationCommandType `json:"type,omitempty"`
101+ Options * []* ApplicationCommandOption `json:"options,omitempty"`
102+ DMPermission * bool `json:"dm_permission,omitempty"` // Global only.
103+ DefaultMemberPermissions * PermissionBit `json:"default_member_permissions,omitempty"`
104+ DefaultPermission * bool `json:"default_permission,omitempty"`
105+ NSFW * bool `json:"nsfw,omitempty"`
89106}
90107
91108type ApplicationCommandQueryBuilder interface {
@@ -95,9 +112,12 @@ type ApplicationCommandQueryBuilder interface {
95112}
96113
97114type ApplicationCommandFunctions interface {
115+ Get (commandId Snowflake ) (* ApplicationCommand , error )
116+ Commands () ([]* ApplicationCommand , error )
98117 Delete (commandId Snowflake ) error
99118 Create (command * CreateApplicationCommand ) error
100119 Update (commandId Snowflake , command * UpdateApplicationCommand ) error
120+ BulkOverwrite (commands []* CreateApplicationCommand ) error
101121}
102122
103123type applicationCommandFunctions struct {
@@ -123,21 +143,67 @@ func applicationCommandFactory() interface{} {
123143 return & ApplicationCommand {}
124144}
125145
146+ func (c * applicationCommandFunctions ) Get (commandID Snowflake ) (* ApplicationCommand , error ) {
147+ var endpoint string
148+ if c .guildID == 0 {
149+ endpoint = fmt .Sprintf ("/applications/%d/commands/%d" , c .applicationID (), commandID )
150+ } else {
151+ endpoint = fmt .Sprintf ("/applications/%d/guilds/%d/commands/%d" , c .applicationID (), c .guildID , commandID )
152+ }
153+
154+ req := & httd.Request {
155+ Endpoint : endpoint ,
156+ Method : http .MethodGet ,
157+ Ctx : c .ctx ,
158+ ContentType : httd .ContentTypeJSON ,
159+ }
160+
161+ r := c .client .newRESTRequest (req , c .flags )
162+ r .factory = applicationCommandFactory
163+
164+ return getApplicationCommand (r .Execute )
165+ }
166+
167+ func (c * applicationCommandFunctions ) Commands () ([]* ApplicationCommand , error ) {
168+ var endpoint string
169+ if c .guildID == 0 {
170+ endpoint = fmt .Sprintf ("/applications/%d/commands" , c .applicationID ())
171+ } else {
172+ endpoint = fmt .Sprintf ("/applications/%d/guilds/%d/commands" , c .applicationID (), c .guildID )
173+ }
174+
175+ req := & httd.Request {
176+ Endpoint : endpoint ,
177+ Method : http .MethodGet ,
178+ Ctx : c .ctx ,
179+ ContentType : httd .ContentTypeJSON ,
180+ }
181+
182+ r := c .client .newRESTRequest (req , c .flags )
183+ r .factory = func () interface {} {
184+ tmp := make ([]* ApplicationCommand , 0 )
185+ return & tmp
186+ }
187+
188+ return getApplicationCommands (r .Execute )
189+ }
190+
126191func (c * applicationCommandFunctions ) Create (command * CreateApplicationCommand ) error {
127192 var endpoint string
128193 if c .guildID == 0 {
129194 endpoint = fmt .Sprintf ("/applications/%d/commands" , c .applicationID ())
130195 } else {
131196 endpoint = fmt .Sprintf ("/applications/%d/guilds/%d/commands" , c .applicationID (), c .guildID )
132197 }
133- ctx := c . ctx
198+
134199 req := & httd.Request {
135200 Endpoint : endpoint ,
136201 Method : http .MethodPost ,
137202 Body : command ,
138- Ctx : ctx ,
203+ Ctx : c . ctx ,
139204 ContentType : httd .ContentTypeJSON ,
140205 }
206+
141207 r := c .client .newRESTRequest (req , c .flags )
142208 r .factory = applicationCommandFactory
143209 _ , err := r .Execute ()
@@ -146,20 +212,21 @@ func (c *applicationCommandFunctions) Create(command *CreateApplicationCommand)
146212
147213func (c * applicationCommandFunctions ) Update (commandID Snowflake , command * UpdateApplicationCommand ) error {
148214 var endpoint string
149- ctx := c .ctx
150215
151216 if c .guildID == 0 {
152- endpoint = fmt .Sprintf ("applications/%d/commands/%d" , c .applicationID (), commandID )
217+ endpoint = fmt .Sprintf ("/ applications/%d/commands/%d" , c .applicationID (), commandID )
153218 } else {
154- endpoint = fmt .Sprintf ("applications/%d/guilds/%d/commands/%d" , c .applicationID (), c .guildID , commandID )
219+ endpoint = fmt .Sprintf ("/ applications/%d/guilds/%d/commands/%d" , c .applicationID (), c .guildID , commandID )
155220 }
221+
156222 req := & httd.Request {
157223 Endpoint : endpoint ,
158224 Method : http .MethodPatch ,
159225 Body : command ,
160- Ctx : ctx ,
226+ Ctx : c . ctx ,
161227 ContentType : httd .ContentTypeJSON ,
162228 }
229+
163230 r := c .client .newRESTRequest (req , c .flags )
164231 r .factory = applicationCommandFactory
165232 _ , err := r .Execute ()
@@ -168,25 +235,51 @@ func (c *applicationCommandFunctions) Update(commandID Snowflake, command *Updat
168235
169236func (c * applicationCommandFunctions ) Delete (commandID Snowflake ) error {
170237 var endpoint string
171- ctx := c .ctx
172238
173239 if c .guildID == 0 {
174- endpoint = fmt .Sprintf ("applications/%d/commands/%d" , c .applicationID (), commandID )
240+ endpoint = fmt .Sprintf ("/ applications/%d/commands/%d" , c .applicationID (), commandID )
175241 } else {
176- endpoint = fmt .Sprintf ("applications/%d/guilds/%d/commands/%d" , c .applicationID (), c .guildID , commandID )
242+ endpoint = fmt .Sprintf ("/ applications/%d/guilds/%d/commands/%d" , c .applicationID (), c .guildID , commandID )
177243 }
244+
178245 req := & httd.Request {
179246 Endpoint : endpoint ,
180247 Method : http .MethodDelete ,
181- Ctx : ctx ,
248+ Ctx : c . ctx ,
182249 ContentType : httd .ContentTypeJSON ,
183250 }
251+
184252 r := c .client .newRESTRequest (req , c .flags )
185253 r .factory = applicationCommandFactory
186254 _ , err := r .Execute ()
187255 return err
188256}
189257
258+ func (c * applicationCommandFunctions ) BulkOverwrite (commands []* CreateApplicationCommand ) error {
259+ var endpoint string
260+ if c .guildID == 0 {
261+ endpoint = fmt .Sprintf ("/applications/%d/commands" , c .applicationID ())
262+ } else {
263+ endpoint = fmt .Sprintf ("/applications/%d/guilds/%d/commands" , c .applicationID (), c .guildID )
264+ }
265+
266+ req := & httd.Request {
267+ Endpoint : endpoint ,
268+ Method : http .MethodPut ,
269+ Body : commands ,
270+ Ctx : c .ctx ,
271+ ContentType : httd .ContentTypeJSON ,
272+ }
273+
274+ r := c .client .newRESTRequest (req , c .flags )
275+ r .factory = func () interface {} {
276+ tmp := make ([]* ApplicationCommand , 0 )
277+ return & tmp
278+ }
279+ _ , err := r .Execute ()
280+ return err
281+ }
282+
190283type applicationCommandQueryBuilder struct {
191284 ctx context.Context
192285 client * Client
@@ -197,6 +290,7 @@ type applicationCommandQueryBuilder struct {
197290func (q applicationCommandQueryBuilder ) Guild (guildId Snowflake ) ApplicationCommandFunctions {
198291 return & applicationCommandFunctions {appID : q .appID , ctx : q .ctx , guildID : guildId , client : q .client , flags : q .flags }
199292}
293+
200294func (q applicationCommandQueryBuilder ) Global () ApplicationCommandFunctions {
201295 return & applicationCommandFunctions {appID : q .appID , ctx : q .ctx , client : q .client , flags : q .flags }
202296}
0 commit comments