Closed JstnMcBrd closed 1 month ago
Restarting the bot fixed the issue. It looks like it was in a bad state. I'm still not sure what caused it.
The error message came from the save()
method inside memory/whitelist.ts
where it calls writeFileSync()
. It indicates that filePath
was an empty string. But filePath
is initialized inside the load()
method, which repeats regularly.
Perhaps the load()
method threw an error, which prevented it from running again, leaving filePath
uninitialized forever. This would leave the whitelist empty, and cause the whitelist/unwhitelist commands to throw errors. Or perhaps the ready
event handler threw an error on startup and never called load()
from the beginning.
After reviewing the logs, it looks like that's exactly what happened.
On Aug 27 14:10:45
, the bot started and threw the following error:
Event handler for "ready" encountered an error:
HTTPError: Internal Server Error
at handleErrors (.../discord-cleverbot/node_modules/@discordjs/rest/dist/index.js:715:11)
at SequentialHandler.runRequest (.../discord-cleverbot/node_modules/@discordjs/rest/dist/index.js:1120:29)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async SequentialHandler.queueRequest (.../discord-cleverbot/node_modules/@discordjs/rest/dist/index.js:953:14)
at async _REST.request (.../discord-cleverbot/node_modules/@discordjs/rest/dist/index.js:1266:22)
at async ApplicationCommandManager.fetch (.../discord-cleverbot/node_modules/discord.js/src/managers/ApplicationCommandManager.js:117:18)
at async syncCommands (file:///.../discord-cleverbot/dist/commands/index.js:44:20)
at async EventHandler.execution (file:///.../discord-cleverbot/dist/events/ready.js:11:5)
at async EventHandler.execute (file:///.../discord-cleverbot/dist/events/EventHandler.js:61:17) {
requestBody: { files: undefined, json: undefined },
status: 500,
method: 'GET',
url: 'https://discord.com/api/v10/applications/388857293657079820/commands'
}
This error happened when trying to sync commands. And syncCommands()
is called before refresh()
, so refreshing was never started, and the whitelist was never initialized.
// src/events/ready.ts
await syncCommands(client);
await refresh(client);
This wasn't discovered until a month later, on Sep 27. That whole time, the bot was not refreshing or recognizing messages from whitelisted channels.
Perhaps refresh()
should be called before syncCommands()
? Still, the larger issue is much of the code is not hardened against errors from the Discord API, and fixing that will require a larger evaluation.
Noticed 2024-09-26 at around 11:58pm MST.
In whitelisted channels, the bot is only replying to messages if they are a direct reply or mention, as if the channel is not whitelisted.
/whitelist
and/unwhitelist
commands throw the following error:Because there has been no recent code changes, this may be from the web server's recent update to Ubuntu 24.04, which briefly broke the
systemctl
run script for CleverBoi. Perhaps it is not fully fixed yet.