/// <summary> /// Mutes the user if they have an active mute infraction in the guild. /// </summary> /// <param name="guild">The guild that the user joined.</param> /// <param name="user">The user who joined the guild.</param> /// <returns> /// A <see cref="Task"/> that will complete when the operation completes. /// </returns> private async Task TryMuteUserAsync(ISocketGuildUser guildUser) { var userHasActiveMuteInfraction = await _moderationService.AnyInfractionsAsync(new InfractionSearchCriteria() { GuildId = guildUser.GuildId, IsDeleted = false, IsRescinded = false, SubjectId = guildUser.Id, Types = new[] { InfractionType.Mute }, }); if (!userHasActiveMuteInfraction) { Log.Debug("User {0} was not muted, because they do not have any active mute infractions.", guildUser.Id); return; } var muteRole = await _moderationService.GetOrCreateDesignatedMuteRoleAsync(guildUser.Guild, _discordSocketClient.CurrentUser.Id); Log.Debug("User {0} was muted, because they have an active mute infraction.", guildUser.Id); await guildUser.AddRoleAsync(muteRole); }