@@ -212,38 +212,50 @@ async def jsk_sync(self, ctx: ContextA, *targets: str):
212
212
paginator = commands .Paginator (prefix = '' , suffix = '' )
213
213
214
214
guilds_set : typing .Set [typing .Optional [int ]] = set ()
215
+ clear_guilds_set : typing .Set [typing .Optional [int ]] = set ()
215
216
for target in targets :
216
- if target == '$' :
217
- guilds_set .add (None )
217
+ active_set = guilds_set
218
+ if target [0 ] == '-' :
219
+ active_set = clear_guilds_set
220
+ target = target [1 :]
221
+ if target == '' or target == '$' :
222
+ active_set .add (None )
218
223
elif target == '*' :
219
- guilds_set |= set (self .bot .tree ._guild_commands .keys ()) # type: ignore # pylint: disable=protected-access
224
+ active_set |= set (self .bot .tree ._guild_commands .keys ()) # type: ignore # pylint: disable=protected-access
220
225
elif target == '.' :
221
226
if ctx .guild :
222
- guilds_set .add (ctx .guild .id )
227
+ active_set .add (ctx .guild .id )
223
228
else :
224
229
await ctx .send ("Can't sync guild commands without guild information" )
225
230
return
226
231
else :
227
232
try :
228
- guilds_set .add (int (target ))
233
+ active_set .add (int (target ))
229
234
except ValueError as error :
230
235
raise commands .BadArgument (f"{ target } is not a valid guild ID" ) from error
231
236
232
237
if not targets :
233
238
guilds_set .add (None )
234
239
235
- guilds : typing .List [typing .Optional [int ]] = list (guilds_set )
236
- guilds .sort (key = lambda g : (g is not None , g ))
240
+ guilds : typing .List [typing .Tuple [typing .Optional [int ], bool ]] = []
241
+ for guild in guilds_set :
242
+ guilds .append ((guild , False ))
243
+ for guild in clear_guilds_set :
244
+ guilds .append ((guild , True ))
245
+ guilds .sort (key = lambda g : (g [0 ] is not None , g ))
237
246
238
- for guild in guilds :
247
+ for guild , clear in guilds :
239
248
slash_commands = self .bot .tree ._get_all_commands ( # type: ignore # pylint: disable=protected-access
240
249
guild = discord .Object (guild ) if guild else None
241
250
)
242
- translator = getattr (self .bot .tree , 'translator' , None )
243
- if translator :
244
- payload = [await command .get_translated_payload (translator ) for command in slash_commands ]
251
+ if clear :
252
+ payload = []
245
253
else :
246
- payload = [command .to_dict () for command in slash_commands ]
254
+ translator = getattr (self .bot .tree , 'translator' , None )
255
+ if translator :
256
+ payload = [await command .get_translated_payload (translator ) for command in slash_commands ]
257
+ else :
258
+ payload = [command .to_dict () for command in slash_commands ]
247
259
248
260
try :
249
261
if guild is None :
0 commit comments