Elliot
Elliot
SIASapphire - Imagine a framework
Created by Elliot on 9/8/2023 in #discordjs-support
How do you handle incompatible null/undefined from discord.js typings?
Note: This is not a typescript problem, I know how to solve it from different ways. I'm just looking for feedbacks or djs-specific answers/workarounds There are a lot of places where discord.js uses a mix of null/undefined and sometimes it gets really frustrating. For example this is a very common occurence in my codebase :
new EmbedBuilder()
.setAuthor({
name: myText,
iconURL: member.user.avatarURL(),
// ^^^^^^^ ^^^^^^^^^^^
// string | undefined string | null
})
new EmbedBuilder()
.setAuthor({
name: myText,
iconURL: member.user.avatarURL(),
// ^^^^^^^ ^^^^^^^^^^^
// string | undefined string | null
})
This leads to a type mismatch which triggers typescript. Is it expected that types within a single library don't match like this? How do you handle this in your discord.js codebase? I'm tired of adding ?? undefined (which makes no sense) or a TS null assertion !… Thank you! (PS: you should update the djs versions in the tags)
16 replies
SIASapphire - Imagine a framework
Created by Elliot on 4/16/2023 in #sapphire-support
More information for CombinedPropertyErrors on shapeshift
Hello, I just rountinely cheked my errors on my production bot and noticed that a few days ago I had the following error
ERROR - Encountered error on event listener "messageUpdate" for event "messageUpdate" at path "./dist/src/listeners/client/messageUpdate.js" CombinedPropertyError (1)
ERROR - Received one or more errors
ERROR -
ERROR - input[1]
ERROR - | [CombinedPropertyError]
ERROR -
ERROR - at ArrayValidator.handle (./node_modules/@sapphire/shapeshift/src/validators/ArrayValidator.ts:95:47)
ERROR - at ArrayValidator.parse (./node_modules/@sapphire/shapeshift/src/validators/BaseValidator.ts:92:2)
ERROR - at EmbedBuilder.addFields (./node_modules/@discordjs/builders/src/messages/embed/Embed.ts:85:29)
ERROR - at logActionUnsafe (./src/lib/structures/logs/DiscordLogManager.ts:296:6)
ERROR - Encountered error on event listener "messageUpdate" for event "messageUpdate" at path "./dist/src/listeners/client/messageUpdate.js" CombinedPropertyError (1)
ERROR - Received one or more errors
ERROR -
ERROR - input[1]
ERROR - | [CombinedPropertyError]
ERROR -
ERROR - at ArrayValidator.handle (./node_modules/@sapphire/shapeshift/src/validators/ArrayValidator.ts:95:47)
ERROR - at ArrayValidator.parse (./node_modules/@sapphire/shapeshift/src/validators/BaseValidator.ts:92:2)
ERROR - at EmbedBuilder.addFields (./node_modules/@discordjs/builders/src/messages/embed/Embed.ts:85:29)
ERROR - at logActionUnsafe (./src/lib/structures/logs/DiscordLogManager.ts:296:6)
Is it expected that i don't have more information on the error ? Because if I understand correctly here the error is just telling me "there was errors", but not telling me which... Is there anything to enable in shapeshift or the logger (object depth?) or idk to have more informations in the future? Because I can't do much with such an unhelpful error btw it happened with the following code, so my guess is that the pupa thing or my contentValue exceeded the field value max length, but i'd have liked the shapeshift error to tell me that..
// EmbedBuilder...
.addFields([
{ name: fieldOptions.contextName, value: pupa(fieldOptions.contextValue, payload), inline: true },
{ name: fieldOptions.contentName, value: contentValue || "oopsie", inline: true },
])
// EmbedBuilder...
.addFields([
{ name: fieldOptions.contextName, value: pupa(fieldOptions.contextValue, payload), inline: true },
{ name: fieldOptions.contentName, value: contentValue || "oopsie", inline: true },
])
Thanks :)
7 replies
SIASapphire - Imagine a framework
Created by Elliot on 2/28/2023 in #sapphire-support
Version mismatch between Sapphire and dapi-types
Hi, I was updating my dependencies when I encountered Discord.js' dapi-types error. I copy/pasted their solution in my package.json (https://discord.com/channels/222078108977594368/769862166131245066/1076213839990894604)
"overrides": {
"discord-api-types": "0.37.20"
}
"overrides": {
"discord-api-types": "0.37.20"
}
Which fixed all the Typescript's compilation errors. But now I have a runtime error with Sapphire failing to resolve dapi-types :
Error: Cannot find module 'discord-api-types/v10'
Require stack:
- ./node_modules/@sapphire/framework/dist/lib/utils/application-commands/ApplicationCommandRegistry.js
- ./node_modules/@sapphire/framework/dist/lib/utils/application-commands/ApplicationCommandRegistries.js
- ./node_modules/@sapphire/framework/dist/index.js
- ./node_modules/@sapphire/plugin-logger/dist/register.js
- ./node_modules/@sapphire/plugin-logger/register.js
- ./dist/src/main.js
Error: Cannot find module 'discord-api-types/v10'
Require stack:
- ./node_modules/@sapphire/framework/dist/lib/utils/application-commands/ApplicationCommandRegistry.js
- ./node_modules/@sapphire/framework/dist/lib/utils/application-commands/ApplicationCommandRegistries.js
- ./node_modules/@sapphire/framework/dist/index.js
- ./node_modules/@sapphire/plugin-logger/dist/register.js
- ./node_modules/@sapphire/plugin-logger/register.js
- ./dist/src/main.js
Versions of relevant deps (everything is latest from NPM) :
"dependencies": {
"@sapphire/async-queue": "^1.5.0",
"@sapphire/decorators": "^6.0.0",
"@sapphire/discord-utilities": "^3.0.0",
"@sapphire/discord.js-utilities": "^6.0.2",
"@sapphire/framework": "^4.2.0",
"@sapphire/plugin-logger": "^3.0.1",
"@sapphire/plugin-subcommands": "^4.0.0",
"@sapphire/stopwatch": "^1.5.0",
"@sapphire/type": "^2.3.0",
"@sapphire/utilities": "^3.11.0",
"discord.js": "^14.7.1",
},
"overrides": {
"discord-api-types": "0.37.20"
},
"dependencies": {
"@sapphire/async-queue": "^1.5.0",
"@sapphire/decorators": "^6.0.0",
"@sapphire/discord-utilities": "^3.0.0",
"@sapphire/discord.js-utilities": "^6.0.2",
"@sapphire/framework": "^4.2.0",
"@sapphire/plugin-logger": "^3.0.1",
"@sapphire/plugin-subcommands": "^4.0.0",
"@sapphire/stopwatch": "^1.5.0",
"@sapphire/type": "^2.3.0",
"@sapphire/utilities": "^3.11.0",
"discord.js": "^14.7.1",
},
"overrides": {
"discord-api-types": "0.37.20"
},
What should I do to fix this runtime error ? 😄 Thanks
13 replies
SIASapphire - Imagine a framework
Created by Elliot on 1/12/2023 in #discordjs-support
BaseMessageOptions#components does not take Builders
Hey everyone, so I've just downloaded djs 14.7.0 and i'm migrating my bot. I used to have a few .send({ components: [myComp] }), where myComp was the equivalent of what is now a Builder. So now i've updated it to a builder, but it is no longer accepted by TypeScript. A few examples:
src/commands/General/code.ts:169:86 - error TS2322: Type 'ActionRowBuilder<AnyComponentBuilder>' is not assignable to type 'APIActionRowComponent<APIMessageActionRowComponent> | JSONEncodable<APIActionRowComponent<APIMessageActionRowComponent>> | ActionRowData<...>'.
Property 'type' is missing in type 'ActionRowBuilder<AnyComponentBuilder>' but required in type 'ActionRowData<MessageActionRowComponentData | MessageActionRowComponentBuilder>'.

169 await prompter.send({ components: [codeMenu(codes)] });
src/commands/General/code.ts:169:86 - error TS2322: Type 'ActionRowBuilder<AnyComponentBuilder>' is not assignable to type 'APIActionRowComponent<APIMessageActionRowComponent> | JSONEncodable<APIActionRowComponent<APIMessageActionRowComponent>> | ActionRowData<...>'.
Property 'type' is missing in type 'ActionRowBuilder<AnyComponentBuilder>' but required in type 'ActionRowData<MessageActionRowComponentData | MessageActionRowComponentBuilder>'.

169 await prompter.send({ components: [codeMenu(codes)] });
src/commands/General/code.ts:211:20 - error TS2322: Type 'ActionRowBuilder<AnyComponentBuilder>' is not assignable to type 'APIActionRowComponent<APIMessageActionRowComponent> | JSONEncodable<APIActionRowComponent<APIMessageActionRowComponent>> | ActionRowData<...>'.

211 components: [wrapConfirmation],
src/commands/General/code.ts:211:20 - error TS2322: Type 'ActionRowBuilder<AnyComponentBuilder>' is not assignable to type 'APIActionRowComponent<APIMessageActionRowComponent> | JSONEncodable<APIActionRowComponent<APIMessageActionRowComponent>> | ActionRowData<...>'.

211 components: [wrapConfirmation],
How can I solve this? Calling .data or .toJSON() does not solve the issue Thanks!
6 replies