Kirollos / Oxide.Ext.Discord

Discord extension and integration
https://umod.org/extensions/discord
MIT License
4 stars 5 forks source link

AddGuildMemberRole not always executing/going through #6

Closed recon88 closed 3 years ago

recon88 commented 3 years ago

There seems to be an issue with the AddGuildMemberRole method. Calling AddGuildMemberRole(DiscordClient client, User user, Role role) doesn't seem to always go through. I don't seem the only one experiencing that issue. There's also a public and a paid umod/rust plugin which are utilizing this method and both fail at it. It sometimes works, but most of the time it doesn't. 7 out of 10 tries just literally do nothing when testing. The code fully executes but the API call seems to fail(?). No errors/warnings in the umod or rust logfile.

Kirollos commented 3 years ago

This function also has a callback action, if you add it, do you get a response from it at all even when it fails?

CC: @dassjosh

recon88 commented 3 years ago

Mind giving me an example of how to use the callback actions @Kirollos ?

Edit: Still couldn't figure out. Would gladly provide the debugging information if someone can get me an example of the said callback actions.

dassjosh commented 3 years ago

I've been testing this out over multiple days and I haven't run into this issue. If you could provide some code samples of what's being run so we can try testing it out that would be appreciated. Looking at our error handling there will always be an error displayed if there is an issue.

Here is the small sample I have been running for a couple hours each day on version 1.0.7

private const string UserId = "196810632517910528";
private const string RoleId = "797212369456857088";
private void DoTest()
{
    var server = _client.DiscordServers[0];
    var member = server.members.FirstOrDefault(m => m.user.id == UserId);

    Puts("Adding Role");
    server.AddGuildMemberRole(_client, UserId, RoleId, () =>
    {
        Puts("Role Added");
        timer.In(1f, () =>
        {
            bool hasRole = member.roles.Contains(RoleId);
            Puts($"Member has role? {hasRole}");

            if (hasRole)
            {
                Puts("Removing Role Role");
                server.RemoveGuildMemberRole(_client, UserId, RoleId, () =>
                {
                    Puts("Removed Role Role");
                    TestDelayed();
                });
            }
            else
            {
                PrintError("ROLE IS MISSING!!!");
                TestDelayed();
            }

        });
    });
}

private void TestDelayed()
{
    timer.In(10, DoTest);
}
recon88 commented 3 years ago

Hey @dassjosh Appreciate the example, but that doesn't actually return the request`s response which is what I would need. Is there any way to get access to that data? AddGuildMemberRole(...) runs through just fine but the user actually doesn't always get assigned the role.

I made a small Rust Plugin with just that method and static IDs, same issue.

The mentioned public Plugin: https://umod.org/plugins/discord-rewards Issue thread (a bit messy with 2 topic): https://umod.org/community/discord-rewards/14804-not-giving-discord-roles Not using that but a private one, which is utilizing the same methods.