SerenityOS/discord-bot

Debug outputting failing

davidot opened this issue · 4 comments

I tried to run the bot locally but ran into the issue that BigInt cannot be serialized in json.
Error: TypeError: Do not know how to serialize a BigInt.
Which is seemingly from memberPermissions being a BigInt.

I fixed it with this but I'm unsure if this is something that I did wrong perhaps:

diff --git a/src/commandHandler.ts b/src/commandHandler.ts
index 2295dd7..f18f0cf 100644
--- a/src/commandHandler.ts
+++ b/src/commandHandler.ts
@@ -78,7 +78,7 @@ export default class CommandHandler {
     /** Executes user commands contained in a message if appropriate. */
     async handleBaseCommandInteraction(interaction: BaseCommandInteraction): Promise<void> {
         if (!this.production) {
-            const msg = `Buggie bot received '${JSON.stringify(interaction)}' from ${
+            const msg = `Buggie bot received '${JSON.stringify(interaction, (_, v) => typeof v === 'bigint' ? v.toString() + 'n' : v)}' from ${
                 interaction.user.tag
             }`;
             await interaction.channel?.send(msg);

Prettier complains about the formatting a little and I would use a template string rather than + 'n' but otherwise LGTM:

const msg = `Buggie bot received '${JSON.stringify(interaction, (_, v) =>
    typeof v === "bigint" ? `${v.toString()}n` : v
)} from '${interaction.user.tag}`;

Any updates on this?

Any updates on this?

Looking at the code it seems the problem is still there. I initially didn't add it to my PR (in october) because I wasn't sure if it was perhaps on my end. I'm not planning to make a PR for just this so feel free to do it.