Skip to content

Conversation

FranjoMindek
Copy link
Contributor

@FranjoMindek FranjoMindek commented Aug 20, 2025

Updates discord.js from v12 to v14.
This also updates Discord API from v8 to v10.
Discord API v8 is deprecated.

Logic behind changes is explained on the changed files themselves.

Fixes: #21

}

cliReport().catch((e) => {
const message = getAnalyticsErrorMessage(e);
Copy link
Contributor Author

@FranjoMindek FranjoMindek Aug 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should let the logger get the error object rather than message.
It has built in formatters to handle errors itself. No need to do it ourselves.

}

export async function handleAnalyticsCommand(
discordClient: Discord.Client,
Copy link
Contributor Author

@FranjoMindek FranjoMindek Aug 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We receive the Discord.Client object inside of the message object.
No need to pass it by ourselves.

Moreover, message.client'sDiscord.Client is sure to be ready (Discord.Client<true>).
This ensures some types don't have the optional flag anymore.

await handleAnalyticsCommand(discordClient, message);
}
async function handleGuildMessage(message: Discord.Message): Promise<void> {
if (message.author.bot) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't handle any bot. That includes this bot itself.

@FranjoMindek FranjoMindek self-assigned this Aug 20, 2025
const embed = new Discord.EmbedBuilder();
embed.setImage(report.imageChartsChart.toURL());
options.embed = embed;
options.embeds = [embed];
Copy link
Contributor Author

@FranjoMindek FranjoMindek Aug 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

discord.js now supports up to 10 embeds, hence plural.

await reportsChannel.send(
`Failed to send daily analytics report: ${message}`,
`Failed to send daily analytics report. Check the logs for more details.
https://fly-metrics.net/d/fly-logs/fly-logs?orgId=273532&var-app=wasp-bot`,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The message was never really to helpful.
I've added a link to our wasp-bot graphana so we can easily check the logs.

This comment was marked as resolved.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm still feels a bit weird that we get an error and don't show it :D.
What if it will be valuable at some point? Let's put it this way also: somebody will get this message, and will wonder "but what is the error", and might go here and return code to the old state. While if they do see the error, maybe it is useless, but at least they know they got all the info they could get, and can move on. Plus, what if it is actually useful?

So I would suggest printing error, it can't hurt can it? Why did you even remove it, because we don't have that helper function anymore so it is a bit harder to get the message from the error?

Copy link
Contributor Author

@FranjoMindek FranjoMindek Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just thought that linking logs dashboard directly would be more helpful than something like:

Failed to send daily analytics report: Request failed with status code 500

Failed to send daily analytics report: Request failed with status code 429
# actaully useful one
Failed to send daily analytics report: Not all events have been fetched: PostHog likely rate-limited us.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can do both, log the message + link to logs.

Copy link
Contributor Author

@FranjoMindek FranjoMindek Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Also the weird fact that last few times it failed it displayed nothing. Hmm.
If it failed inside of "total" report it should have been sent.

Maybe I should explore this more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah maybe there is some deeper issue (well almost certainly hm).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added the error message logging back. If it's an Error type it should print the error.message by default when appending the error to a string.

@FranjoMindek FranjoMindek marked this pull request as ready for review August 21, 2025 08:24
Copy link
Member

@cprecioso cprecioso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM, left some comments

@FranjoMindek FranjoMindek requested a review from cprecioso August 21, 2025 10:16
Copy link
Contributor

@infomiho infomiho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments

Copy link
Contributor

@infomiho infomiho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@Martinsos Martinsos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@FranjoMindek nice work! I approved, but left some comments, please take care of those and I am all good.

await reportsChannel.send(
`Failed to send daily analytics report: ${message}`,
`Failed to send daily analytics report. Check the logs for more details.
https://fly-metrics.net/d/fly-logs/fly-logs?orgId=273532&var-app=wasp-bot`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm still feels a bit weird that we get an error and don't show it :D.
What if it will be valuable at some point? Let's put it this way also: somebody will get this message, and will wonder "but what is the error", and might go here and return code to the old state. While if they do see the error, maybe it is useless, but at least they know they got all the info they could get, and can move on. Plus, what if it is actually useful?

So I would suggest printing error, it can't hurt can it? Why did you even remove it, because we don't have that helper function anymore so it is a bit harder to get the message from the error?

Comment on lines 31 to 33
// We also need to enable Privileged Gateway Intents in the Discord Developer Portal.
// As of now those are: `Server Members Intent` and `Message Content Intent`
// See: https://discordjs.guide/popular-topics/intents.html#gateway-intents
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like a TODO: "We also need to ...".

Maybe instead turn it into:

// NOTE:
// We assume that Privileged Gateway Intents were manually enabled in the Discord Developer Portal.

Because it is documentation of an assumption required for this code to work.

Also make sure to mention this in the README.md .

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it has NOTE in front of it 😭 .

How about

// NOTE:
// If Privileged Gateway Intents are not enable in the Discord Developer Portal,
// the bot will throw an error on startup.
// As of now those are: `Server Members Intent` and `Message Content Intent`
// See: https://discordjs.guide/popular-topics/intents.html#gateway-intents

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok yeah, taht sounds good also! enableD (typo).

}

discordClient.on("messageUpdate", async (_oldMessage, newMessage) => {
// TODO: Actually handle partial messages.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is handled now? We enabled them in Discord.Client? Is that manually done or here in the code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discord no longer sends partial messages to message update event. So we don't have to handle them separately.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never a big fan of types.ts/hs files. In general we avoid them. But I don't know here waht is a better name, maybe you know.

raw

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sometimes some types in TS are global helpers. Hard to domain them when their purpose is to work with TS type system and not with worldly domain.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But these are domain aren't they? Discord?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is used in that domain but the type itself is a general TS type helper. That's what I meant.

Copy link
Member

@Martinsos Martinsos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved again :D! You don't need me to look again, handle comments as you see fit.

@FranjoMindek FranjoMindek merged commit e916b8c into master Sep 19, 2025
FranjoMindek added a commit that referenced this pull request Sep 19, 2025
@FranjoMindek FranjoMindek deleted the franjo/update-discordjs branch September 19, 2025 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update discord.js library
4 participants