first off, I know, that my question is very bad formulated. I am sorry for that.
I am trying to get my bot to search the status of every user in a guild and if the users status contains a certain string, the user gets a role. Everything works, as it should, aside from one thing. I want to run the command once and the other command will run every x seconds, so the users get updated all the time.
Now, if I add the string to my status and run the bot, it gives me the role every run. when I remove it, while the bot is running, the bot somehow still keeps giving me the role (it is supposed to remove the role and shut up until I add the string again). So it is somehow not updating and thinks, I stil have the role.
I am open for suggestions.
heres the responisble code:
[Command("statuson")]
[Alias("x")]
public async Task StatusOn()
{
while (true)
{
Console.WriteLine("req refresh");
await JaLOL();
Thread.Sleep(10000);
}
}
public int count = 0;
public async Task JaLOL()
{
IReadOnlyCollection<SocketGuildUser> users = null;
IReadOnlyCollection<IActivity> userActivities = null;
IReadOnlyCollection<ulong> roles = null;
Console.WriteLine("refresh");
users = Context.Guild.Users;
foreach (IGuildUser user in users)
{
userActivities = user.Activities;
roles = user.RoleIds;
foreach (ulong role in roles)
{
if (role == 1020762686323167303)
{
foreach (var activity in userActivities)
{
if (activity.Type == ActivityType.CustomStatus)
{
if (!activity.ToString().Contains(".gg/anime-club"))
{
await user.RemoveRoleAsync(1020762686323167303);
Console.WriteLine("remove " + user.DisplayName);
}
}
}
}
}
foreach (var activity in userActivities)
{
if (activity.Type == ActivityType.CustomStatus)
{
if (activity.ToString().Contains(".gg/anime-club"))
{
await user.AddRoleAsync(1020762686323167303);
Console.WriteLine("add " + user.DisplayName);
}
}
}
}
count++;
Console.WriteLine("end " + count);
}