diff --git a/TrickfireCheckIn/Discord/Bot.cs b/TrickfireCheckIn/Discord/Bot.cs index bb3f9c2..6ab76b9 100644 --- a/TrickfireCheckIn/Discord/Bot.cs +++ b/TrickfireCheckIn/Discord/Bot.cs @@ -55,23 +55,27 @@ public Bot(string token) Client = builder.Build(); // Subscribe to updates of member list + object lock_ = new(); State.Members.CollectionChanged += (_, ev) => { - _needToUpdateEmbed = true; + lock(lock_) + { + _needToUpdateEmbed = true; - IEnumerable oldItems = (ev.OldItems ?? new List()) - .Cast<(DiscordMember, DateTimeOffset)>() - .Select(val => val.Item1.DisplayName); + IEnumerable oldItems = (ev.OldItems ?? new List()) + .Cast<(DiscordMember, DateTimeOffset)>() + .Select(val => val.Item1.DisplayName); - IEnumerable newItems = (ev.NewItems ?? new List()) - .Cast<(DiscordMember, DateTimeOffset)>() - .Select(val => val.Item1.DisplayName); + IEnumerable newItems = (ev.NewItems ?? new List()) + .Cast<(DiscordMember, DateTimeOffset)>() + .Select(val => val.Item1.DisplayName); - Client.Logger.LogInformation( - "Member collection changed: {}\nOld items: {}\nNew items: {}", - ev.Action.ToString(), - string.Join(", ", oldItems), - string.Join(", ", newItems)); + Client.Logger.LogInformation( + "Member collection changed: {}\nOld items: {}\nNew items: {}", + ev.Action.ToString(), + string.Join(", ", oldItems), + string.Join(", ", newItems)); + } }; }