-
Notifications
You must be signed in to change notification settings - Fork 4
Update discord.js
to latest version
#59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
@@ -91,6 +90,5 @@ function printAllTimeMonthlyReportCsvInCLI( | |||
} | |||
|
|||
cliReport().catch((e) => { | |||
const message = getAnalyticsErrorMessage(e); |
There was a problem hiding this comment.
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.
@@ -22,22 +22,21 @@ function isReportsChannel(channel: Discord.Channel): boolean { | |||
} | |||
|
|||
export async function handleAnalyticsCommand( | |||
discordClient: Discord.Client, |
There was a problem hiding this comment.
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.
if (isOurDiscordBotMessage(discordClient, message)) { | ||
return; | ||
} | ||
await discordClient.login(BOT_TOKEN); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is async, we should await and make start
an async function.
Then the caller can decide if to await or not.
Like this the caller has no choice to await.
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
await handleAnalyticsCommand(discordClient, message); | ||
} | ||
async function handleGuildMessage(message: Discord.Message): Promise<void> { | ||
if (message.author.bot) { |
There was a problem hiding this comment.
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.
src/discord/bot/analytics/common.ts
Outdated
embed.setImage(report.imageChartsChart.toURL()); | ||
options.embed = embed; | ||
options.embeds = [embed]; |
There was a problem hiding this comment.
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`, |
There was a problem hiding this comment.
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.
This comment was marked as resolved.
Sorry, something went wrong.
Discord.GatewayIntentBits.Guilds, | ||
Discord.GatewayIntentBits.GuildMessages, | ||
Discord.GatewayIntentBits.GuildMembers, | ||
Discord.GatewayIntentBits.MessageContent, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have to add those intents to our bot's settings on Discord's developers portal.
Otherwise we will error on startup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Classic comment, but I'd add this to the code itself for the future when people update the code to go and update the settings.
There was a problem hiding this 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
if (isOurDiscordBotMessage(discordClient, message)) { | ||
return; | ||
} | ||
await discordClient.login(BOT_TOKEN); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some comments
Discord.GatewayIntentBits.Guilds, | ||
Discord.GatewayIntentBits.GuildMessages, | ||
Discord.GatewayIntentBits.GuildMembers, | ||
Discord.GatewayIntentBits.MessageContent, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Classic comment, but I'd add this to the code itself for the future when people update the code to go and update the settings.
src/discord/bot/index.ts
Outdated
|
||
await handleMessage(newMessage); | ||
}); | ||
// Messages sent in DM channels |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Messages sent in DM channels | |
// Ignore messages sent in the DM channels |
src/discord/bot/index.ts
Outdated
], | ||
}); | ||
|
||
discordClient.on(Discord.Events.ClientReady, (readyDiscordClient) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
discordClient.on(Discord.Events.ClientReady, (readyDiscordClient) => { | |
discordClient.on(Discord.Events.ClientReady, (startedDiscordClient) => { |
Nitpick: the ready
adjective can also read as a verb so it confused me for a second if this is a function or a "Discord client that is ready", so I think we maybe can improve the name here. Offered my suggestion above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, I use ready
since that is what discord.js
uses, and I didn't want to introduce another domain context. But since this is really local we could go with started
.
src/discord/bot/introduction.ts
Outdated
return !!member?.roles.cache.get(GUEST_ROLE_ID); | ||
async function isGuestUser(message: GuildMessage): Promise<boolean> { | ||
const member = await message.guild.members.fetch(message.author.id); | ||
return Boolean(member.roles.resolve(GUEST_ROLE_ID)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This bit feels a little bit convoluted, what is the value of member.roles.resolve(GUEST_ROLE_ID)
? Is it something or null
and that's why we wrap it into Boolean
to get an implicit conversion to false
if null
?
I'd go for something explicit like member.roles.resolve(GUEST_ROLE_ID) !== null
.
-readonly [K in keyof T]: T[K]; | ||
}; | ||
|
||
export type DeepWritable<T> = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If not used, maybe we can remove this util?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My reason is that it makes it easier to understand Writable
is not recursive.
We can remove.
const options: Discord.MessageOptions = {}; | ||
): Discord.MessageCreateOptions { | ||
const options: Discord.MessageCreateOptions = {}; | ||
const embeds: Writable<Discord.MessageCreateOptions["embeds"]> = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This threw me off a bit since it's removing readonly
for an array of something and I expected Writeable
to work on objects only. But I guess this is the way to do it since you need their type that readonly
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this one is hard to do.
Shame they didn't extract their "files" and "embeds" into separate types before making them readonly
.
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 explain on the changed files themselves.