harmonyland / harmony

An easy to use Discord API Library for Deno.
https://harmony.mod.land
MIT License
321 stars 48 forks source link

[Bug] Bot Randomly Crashes #371

Open Tnology opened 1 year ago

Tnology commented 1 year ago

What's the bug? My bot, which uses Harmony, will sometimes crash at random with an "Uncaught DiscordAPIError".

How do we reproduce it? I'm unable to consistently reproduce the error. My bot will randomly crash if I leave it running, and I'm not sure about how it's triggered. The code to my bot is here: https://github.com/Tnology/TnologyDiscordBot

What should have happened? The bot is supposed to function properly and not crash.

What is actually happening? While my bot is running, the bot randomly crashes with an error as seen below:

error: Uncaught DiscordAPIError:
GET /guilds/471700758354460672/members/1017989345292058656 returned 404
(10007) Unknown Member
      throw new DiscordAPIError({
            ^
    at BucketHandler.execute (https://raw.githubusercontent.com/harmonyland/harmony/daca400ae9feab19604381abddbdab16aa1ede2b/src/rest/bucket.ts:224:13)
    at eventLoopTick (ext:core/01_core.js:183:11)
    at async BucketHandler.push (https://raw.githubusercontent.com/harmonyland/harmony/daca400ae9feab19604381abddbdab16aa1ede2b/src/rest/bucket.ts:55:13)
    at async RESTManager.make (https://raw.githubusercontent.com/harmonyland/harmony/daca400ae9feab19604381abddbdab16aa1ede2b/src/rest/manager.ts:236:12)
    at async RESTManager.get (https://raw.githubusercontent.com/harmonyland/harmony/daca400ae9feab19604381abddbdab16aa1ede2b/src/rest/manager.ts:259:12)
    at async MemberRolesManager._resolveMemberPayload (https://raw.githubusercontent.com/harmonyland/harmony/daca400ae9feab19604381abddbdab16aa1ede2b/src/managers/memberRoles.ts:22:23)
    at async MemberRolesManager.array (https://raw.githubusercontent.com/harmonyland/harmony/daca400ae9feab19604381abddbdab16aa1ede2b/src/managers/memberRoles.ts:50:17)
[root@vps TnologyDiscordBot]# 

The bot fully stops as a result of the crash and needs to be restarted.

What versions you're using?

Do you have anything to tell us more about the bug? I attempted to use an unhandledrejection event handler, but it doesn't really work in my bot's code. Here is the code that I tried with my bot:

// unhandledrejection.js
globalThis.addEventListener("unhandledrejection", (e) => {
  console.log("unhandled rejection at:", e.promise, "reason:", e.reason);
  e.preventDefault();
});

function Foo() {
  this.bar = Promise.reject(new Error("bar not available"));
}

new Foo();
Promise.reject();

Source: Deno Docs, https://deno.com/blog/v1.24#unhandledrejection-event

Instead, here is the output that I get (trying to run on Windows 11, as I am testing from VS Code):

C:\Users\Tyler\Documents\GitHub\TnologyDiscordBot>deno run -A main.ts
error: Uncaught Error: bar not available
    this.bar = Promise.reject(new Error("bar not available"));
                              ^
    at new Foo (file:///C:/Users/Tyler/Documents/GitHub/TnologyDiscordBot/main.ts:718:31)
    at file:///C:/Users/Tyler/Documents/GitHub/TnologyDiscordBot/main.ts:721:3
    at eventLoopTick (ext:core/01_core.js:183:11)

C:\Users\Tyler\Documents\GitHub\TnologyDiscordBot>

It works in the Deno CLI when I just run deno and paste the code there, but not with my bot. I'm not sure why.

arija-ari commented 1 month ago
GET /guilds/471700758354460672/members/1017989345292058656 returned 404
(10007) Unknown Member

tells you it. You are doing something with members and for some reason the member is not found in the guild. Just a guess:

You might do something with your server members after receiving and holding a list of them? What happens if a member leaves your server in the meantime? It might be the culprit. I think you need to refetch your members and validate the member still being in your server.

Just a guess, I'm not really playing with the member API at all, but that's what it reads to me. 😇