Maze error - paginated message

I am getting this on a paginated message
Solution:
I replicated them 1:1, see last commit on the branch
Jump to solution
35 Replies
Slime
SlimeOP14mo ago
public async chatInputCredits(interaction: Subcommand.ChatInputCommandInteraction) {
await interaction.deferReply()
await this.creditsBuilder().run(interaction)
}
public async chatInputCredits(interaction: Subcommand.ChatInputCommandInteraction) {
await interaction.deferReply()
await this.creditsBuilder().run(interaction)
}
Favna
Favna14mo ago
list your dependencies please
Slime
SlimeOP14mo ago
"dependencies": {
"@prisma/client": "^5.4.2",
"@sapphire/decorators": "^6.0.2",
"@sapphire/discord-utilities": "^3.1.1",
"@sapphire/discord.js-utilities": "7.0.2",
"@sapphire/fetch": "^2.4.1",
"@sapphire/framework": "^4.7.1",
"@sapphire/plugin-api": "^5.1.1",
"@sapphire/plugin-editable-commands": "^3.0.3",
"@sapphire/plugin-hmr": "^2.0.2",
"@sapphire/plugin-i18next": "^6.0.1",
"@sapphire/plugin-logger": "^3.0.6",
"@sapphire/plugin-subcommands": "^4.2.2",
"@sapphire/time-utilities": "^1.7.10",
"@sapphire/type": "^2.4.0",
"@sapphire/utilities": "^3.13.0",
"@skyra/env-utilities": "^1.2.1",
"@types/uuid": "^9.0.6",
"axios": "^1.5.1",
"bufferutil": "^4.0.8",
"colorette": "^2.0.20",
"discord.js": "^14.13.0",
"prisma": "^5.4.2",
"uuid": "^9.0.0",
"ws": "^8.14.2"
},
"devDependencies": {
"@commitlint/cli": "^18.1.0",
"@commitlint/config-conventional": "^18.1.0",
"@sapphire/cli": "^1.6.1",
"@sapphire/prettier-config": "^2.0.0",
"@sapphire/ts-config": "^5.0.0",
"@swc/core": "^1.3.95",
"@types/node": "^20.8.7",
"@types/ws": "^8.5.8",
"cpy": "^10.1.0",
"discord-api-types": "^0.37.61",
"npm-run-all": "^4.1.5",
"prettier": "^3.0.3",
"rimraf": "^5.0.5",
"tsc-watch": "^6.0.4",
"tsconfig-paths": "^4.2.0",
"tsup": "^7.2.0",
"typescript": "^5.2.2"
},
"dependencies": {
"@prisma/client": "^5.4.2",
"@sapphire/decorators": "^6.0.2",
"@sapphire/discord-utilities": "^3.1.1",
"@sapphire/discord.js-utilities": "7.0.2",
"@sapphire/fetch": "^2.4.1",
"@sapphire/framework": "^4.7.1",
"@sapphire/plugin-api": "^5.1.1",
"@sapphire/plugin-editable-commands": "^3.0.3",
"@sapphire/plugin-hmr": "^2.0.2",
"@sapphire/plugin-i18next": "^6.0.1",
"@sapphire/plugin-logger": "^3.0.6",
"@sapphire/plugin-subcommands": "^4.2.2",
"@sapphire/time-utilities": "^1.7.10",
"@sapphire/type": "^2.4.0",
"@sapphire/utilities": "^3.13.0",
"@skyra/env-utilities": "^1.2.1",
"@types/uuid": "^9.0.6",
"axios": "^1.5.1",
"bufferutil": "^4.0.8",
"colorette": "^2.0.20",
"discord.js": "^14.13.0",
"prisma": "^5.4.2",
"uuid": "^9.0.0",
"ws": "^8.14.2"
},
"devDependencies": {
"@commitlint/cli": "^18.1.0",
"@commitlint/config-conventional": "^18.1.0",
"@sapphire/cli": "^1.6.1",
"@sapphire/prettier-config": "^2.0.0",
"@sapphire/ts-config": "^5.0.0",
"@swc/core": "^1.3.95",
"@types/node": "^20.8.7",
"@types/ws": "^8.5.8",
"cpy": "^10.1.0",
"discord-api-types": "^0.37.61",
"npm-run-all": "^4.1.5",
"prettier": "^3.0.3",
"rimraf": "^5.0.5",
"tsc-watch": "^6.0.4",
"tsconfig-paths": "^4.2.0",
"tsup": "^7.2.0",
"typescript": "^5.2.2"
},
creditsBuilder(): PaginatedMessage {
return new PaginatedMessage({
template: new EmbedBuilder()
.setColor(BrandingColors.Primary)
.setTitle('Credits')
.setTimestamp()
}).setSelectMenuOptions((pageIndex) => ({ label: ['Page', pageIndex + 1].join(' '), value: pageIndex.toString() }))
.addPageEmbed((embed) => embed.setDescription('Page 1'))
.addPageEmbed((embed) => embed.setDescription('Page 2'))
};
creditsBuilder(): PaginatedMessage {
return new PaginatedMessage({
template: new EmbedBuilder()
.setColor(BrandingColors.Primary)
.setTitle('Credits')
.setTimestamp()
}).setSelectMenuOptions((pageIndex) => ({ label: ['Page', pageIndex + 1].join(' '), value: pageIndex.toString() }))
.addPageEmbed((embed) => embed.setDescription('Page 1'))
.addPageEmbed((embed) => embed.setDescription('Page 2'))
};
Favna
Favna14mo ago
I cannot reproduce the issue. Make sure your dependencies are properly installed by removing your lockfile and node_modules then reinstalling. Also make sure if you're using TypeScript that you remove your compiled files and recompile.
Slime
SlimeOP14mo ago
One moment I will try Hmm still the same with yarn install and after wiping all
Favna
Favna14mo ago
yarn version?
Slime
SlimeOP14mo ago
yarn version v1.22.19 info Current version: 1.0.0 hmm, this seems really old?
Sapphire
Sapphire14mo ago
Yarn v3 is new version of Yarn that we recommend switching to as Yarn v1 has been deprecated.
"But I don't see any update on [source]?"
That is correct. Yarn v3 is installed through Yarn itself. Your global toolchain is and will always remain to be Yarn v1, however, you configure Yarn v3 on a per-project basis. How? Simply write:
yarn set version berry
yarn set version berry
This will download the new Yarn v3 binary and put in .yarn/releases, you should push this to your Git repository. It will also create a .yarnrc.yml file which configures the path which you should also commit. Next you probably also want to run the following 2 commands:
yarn config set enableGlobalCache true
yarn config set nodeLinker node-modules
yarn config set enableGlobalCache true
yarn config set nodeLinker node-modules
This will add to your .yarnrc file:
enableGlobalCache: true
nodeLinker: node-modules
enableGlobalCache: true
nodeLinker: node-modules
Which ensures that you just have a Yarn v1-like experience with node_modules and a global cache. Next step is to nuke your node_modules and yarn.lock and run yarn install Then some final adjustments. Put this in you .gitignore:
# Yarn files
.yarn/install-state.gz
.yarn/build-state.yml
# Yarn files
.yarn/install-state.gz
.yarn/build-state.yml
And anywhere in your scripts in package.json where you use * you should wrap it in extra " For example:
{
"format": "prettier --write \"src/**/*.ts\""
}
{
"format": "prettier --write \"src/**/*.ts\""
}
Mind you this last thing is good add regardless of script runner / package bundler because it ensures the glob is performed by the library and not by your shell, which may differ when people develop on different operating systems. In short the command to set everything up you can run:
yarn set version berry && yarn config set enableGlobalCache true && yarn config set nodeLinker node-modules && echo "" >> .gitignore && echo "# Yarn files" >> .gitignore && echo ".yarn/install-state.gz" >> .gitignore && echo ".yarn/build-state.yml" >> .gitignore
yarn set version berry && yarn config set enableGlobalCache true && yarn config set nodeLinker node-modules && echo "" >> .gitignore && echo "# Yarn files" >> .gitignore && echo ".yarn/install-state.gz" >> .gitignore && echo ".yarn/build-state.yml" >> .gitignore
Favna
Favna14mo ago
v4*, same steps tho
Slime
SlimeOP14mo ago
so it should still be berry?
Favna
Favna14mo ago
yes
Slime
SlimeOP14mo ago
ah I see thank you I just did all this thank you, but I still get the same error, so I will try troubleshoot more The whole file is
import {Subcommand} from '@sapphire/plugin-subcommands';
import {applyLocalizedBuilder} from "@sapphire/plugin-i18next";
import {EmbedBuilder} from "discord.js";
import {BrandingColors} from "#lib/constants";
import {PaginatedMessage} from "@sapphire/discord.js-utilities";

export class AiuraCommand extends Subcommand {
public constructor(context: Subcommand.Context, options: Subcommand.Options) {
super(context, {
...options,
name: 'aiura',
subcommands: [
{
name: 'credits',
chatInputRun: 'chatInputCredits'
}
]
});
}

override registerApplicationCommands(registry: Subcommand.Registry) {
registry.registerChatInputCommand((builder) =>
applyLocalizedBuilder(builder, 'commands/names:aiura', 'commands/descriptions:aiura')
.addSubcommand((command) =>
applyLocalizedBuilder(command, 'commands/names:aiura-credits', 'commands/descriptions:aiura-credits')
)
);
}

public async chatInputCredits(interaction: Subcommand.ChatInputCommandInteraction) {
await interaction.deferReply()
await this.creditsBuilder().run(interaction)
}

/**
* Generates an embed message containing the credits for the bot.
*
* @return {EmbedBuilder} The generated embed message containing the credits.
*/
creditsBuilder(): PaginatedMessage {
return new PaginatedMessage({
template: new EmbedBuilder()
.setColor(BrandingColors.Primary)
.setTitle('Credits')
.setTimestamp()
}).setSelectMenuOptions((pageIndex) => ({ label: ['Page', pageIndex + 1].join(' '), value: pageIndex.toString() }))
.addPageEmbed((embed) => embed.setDescription('Page 1'))
.addPageEmbed((embed) => embed.setDescription('Page 2'))
};
}
import {Subcommand} from '@sapphire/plugin-subcommands';
import {applyLocalizedBuilder} from "@sapphire/plugin-i18next";
import {EmbedBuilder} from "discord.js";
import {BrandingColors} from "#lib/constants";
import {PaginatedMessage} from "@sapphire/discord.js-utilities";

export class AiuraCommand extends Subcommand {
public constructor(context: Subcommand.Context, options: Subcommand.Options) {
super(context, {
...options,
name: 'aiura',
subcommands: [
{
name: 'credits',
chatInputRun: 'chatInputCredits'
}
]
});
}

override registerApplicationCommands(registry: Subcommand.Registry) {
registry.registerChatInputCommand((builder) =>
applyLocalizedBuilder(builder, 'commands/names:aiura', 'commands/descriptions:aiura')
.addSubcommand((command) =>
applyLocalizedBuilder(command, 'commands/names:aiura-credits', 'commands/descriptions:aiura-credits')
)
);
}

public async chatInputCredits(interaction: Subcommand.ChatInputCommandInteraction) {
await interaction.deferReply()
await this.creditsBuilder().run(interaction)
}

/**
* Generates an embed message containing the credits for the bot.
*
* @return {EmbedBuilder} The generated embed message containing the credits.
*/
creditsBuilder(): PaginatedMessage {
return new PaginatedMessage({
template: new EmbedBuilder()
.setColor(BrandingColors.Primary)
.setTitle('Credits')
.setTimestamp()
}).setSelectMenuOptions((pageIndex) => ({ label: ['Page', pageIndex + 1].join(' '), value: pageIndex.toString() }))
.addPageEmbed((embed) => embed.setDescription('Page 1'))
.addPageEmbed((embed) => embed.setDescription('Page 2'))
};
}
Favna
Favna14mo ago
FWIW the error should only occur when you run into an uncaught and unexpected error so something you're doing is going really wrong. FYI you dont need to specify types in JSDoc when you write TS. Also creditsBuilder doesn't return an EmbedBuilder anyway
Slime
SlimeOP14mo ago
Is there a way to get more error logging? Cause nothing shows up in console Doing this works
public async chatInputCredits(interaction: Subcommand.ChatInputCommandInteraction) {
await interaction.deferReply()
// await this.creditsBuilder().run(interaction)
}
public async chatInputCredits(interaction: Subcommand.ChatInputCommandInteraction) {
await interaction.deferReply()
// await this.creditsBuilder().run(interaction)
}
so I assume it's something I do with the PaginatedMessage that's causing an issue
Favna
Favna14mo ago
add a breakpoint in the files in node_modules/@sapphire/discord.js-utilities/dist/index.js and run with a debugger
Favna
Favna14mo ago
GitHub
utilities/packages/discord.js-utilities/src/lib/PaginatedMessages/P...
Common JavaScript utilities for Sapphire Projects. Contribute to sapphiredev/utilities development by creating an account on GitHub.
Slime
SlimeOP14mo ago
and my dependancies looked fine?
Solution
Favna
Favna14mo ago
I replicated them 1:1, see last commit on the branch
Slime
SlimeOP14mo ago
ohh yeah I am going to check out my scripts, and bundling stuff I do as I have some scripts to bundle the json files so I assume it may be causing some chaotic stuff there I will copy your package.json exactly and see if it works
Favna
Favna14mo ago
gl
Slime
SlimeOP14mo ago
But yeah I think this issue can be marked as resolved, as it works when you reproduce I will investigate on my end
Favna
Favna14mo ago
regarding bundling json, not sure what build tool you use but if you use regular tsc you can just have them be moved to dist by including them, i.e. src/**/*.json and resolveJsonModules to true
Slime
SlimeOP14mo ago
I was using tsup
Favna
Favna14mo ago
ah that should work too
Slime
SlimeOP14mo ago
Hmm, even with normal package it doesn't work so yeah there is something going wrong somewhere else I will try to troubleshoot but I will recreate the entire project, thank you!
Favna
Favna14mo ago
what I recommend is setting that breakpoint just before the error is thrown, I linked the line above but you'll have to do a bit of searching (control+f is your friend) in the JS file because it's compiled code. Once on the breakpoint you can check the stack to see where it was called from and work your way upward from there. You should find it quite fast enough.
Slime
SlimeOP14mo ago
So I am trying to debug it but how would I know exactly where the problem is? It doesn't seem obvious at a glaring point, like
Slime
SlimeOP14mo ago
No description
Slime
SlimeOP14mo ago
not sure if it's this but it seems to be related I think
Favna
Favna14mo ago
didnt get back to you before @Slime. I can try and debug it for you but you'll have to send me your code but preferebly in a minimal way. I.e. no database (just cumbersome for me to set up) and only the one command. Also make sure you absolutely include a package lock file (package-lock.json, yarn.lock, etc) so I can be sure to install the same dependencies as you.
Slime
SlimeOP14mo ago
It worked with adding intents So I should have read the docs for that one, I realized by debugging it So it's all good now, I just had some issues setting up the debugging.
Favna
Favna14mo ago
oh ok so you were missing the guilds intent then?
Slime
SlimeOP14mo ago
I didn't have any intents at all but I added the most common ones that I'll think I need but guilds was one of them so adding the intents helped but not sure which one actually solved it
Favna
Favna14mo ago
guilds for sure considering that's the only one @Dragonite has and it works just fine just try /pokemon for example
Want results from more Discord servers?
Add your server