Warn counter reseting and not updating

I write a discord command with warns and dictionaries but each time, my warn counter returns to 0 when I redo the command for the member concerned, someone know how to resolve this ?
1 Reply
P A T R I C K
P A T R I C KOP3y ago
private readonly Dictionary<ulong, Dictionary<ulong, int>> _warns = new();

public async Task WarnGuildMemberAsync(SocketGuildUser member, [Remainder] string? reason = null)
{
ulong guildId = Context.Guild.Id;
ulong memberId = member.Id;

if (!_warns.ContainsKey(guildId))
{
_warns[guildId] = new(); // new() => Dictionary<ulong, int> | ulong key contains the member id
}

if (!_warns[guildId].ContainsKey(memberId))
{
_warns[guildId][memberId] = 0;
}

Console.WriteLine(_warns[guildId][memberId]);
_warns[guildId][memberId]++;
Console.WriteLine(_warns[guildId][memberId]);
}
private readonly Dictionary<ulong, Dictionary<ulong, int>> _warns = new();

public async Task WarnGuildMemberAsync(SocketGuildUser member, [Remainder] string? reason = null)
{
ulong guildId = Context.Guild.Id;
ulong memberId = member.Id;

if (!_warns.ContainsKey(guildId))
{
_warns[guildId] = new(); // new() => Dictionary<ulong, int> | ulong key contains the member id
}

if (!_warns[guildId].ContainsKey(memberId))
{
_warns[guildId][memberId] = 0;
}

Console.WriteLine(_warns[guildId][memberId]);
_warns[guildId][memberId]++;
Console.WriteLine(_warns[guildId][memberId]);
}

Did you find this page helpful?