Skip to content

Commit

Permalink
fix: fix registration of applicaiton commands when commands cleared o…
Browse files Browse the repository at this point in the history
…r non existent in advance
  • Loading branch information
TheXorog committed Jan 17, 2024
1 parent 59ad839 commit f6af29e
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions DisCatSharp.ApplicationCommands/Workers/RegistrationWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -356,14 +356,13 @@ internal class RegistrationWorker
/// <returns></returns>
private static List<DiscordApplicationCommand>? BuildGuildCreateList(DiscordClient client, ulong guildId, List<DiscordApplicationCommand>? updateList = null)
{
if (ApplicationCommandsExtension.GuildDiscordCommands.Count is 0
|| updateList is null || !ApplicationCommandsExtension.GuildDiscordCommands!.TryGetFirstValueByKey(guildId, out var discord)
)
if (updateList is null)
return null;

var success = ApplicationCommandsExtension.GuildDiscordCommands.TryGetFirstValueByKey(guildId, out var discord);
List<DiscordApplicationCommand> newCommands = [];

if (discord is null)
if (!success || discord is null || discord.Count is 0)
return updateList;

newCommands.AddRange(updateList.Where(cmd => discord.All(d => d.Name != cmd.Name)));
Expand Down Expand Up @@ -450,14 +449,14 @@ private static (
/// <returns>A list of commands.</returns>
private static List<DiscordApplicationCommand>? BuildGlobalCreateList(DiscordClient client, List<DiscordApplicationCommand>? updateList = null)
{
if (ApplicationCommandsExtension.GlobalDiscordCommands.Count is 0 || updateList is null)
return updateList;
if (updateList is null)
return null;

var discord = ApplicationCommandsExtension.GlobalDiscordCommands;

List<DiscordApplicationCommand> newCommands = [];

if (discord is null)
if (discord is null || discord.Count is 0)
return updateList;

newCommands.AddRange(updateList.Where(cmd => discord.All(d => d.Name != cmd.Name)));
Expand Down

0 comments on commit f6af29e

Please sign in to comment.