Caspian Nightworth
Caspian Nightworth
Explore posts from servers
SIASapphire - Imagine a framework
Created by Caspian Nightworth on 11/26/2023 in #sapphire-support
Paginination limitation when not using select menus
I have the following error being presented to me
(node:1484241) [PAGINATED_MESSAGE_EXCEEDED_MAXIMUM_AMOUNT_OF_PAGES] PaginatedMessageExceededMessagePageAmount: Maximum amount of pages exceeded for PaginatedMessage. Please check your instance of PaginatedMessage and ensure that you do not exceed 25 pages total. If you do need more than 25 pages you can extend the class and overwrite the actions in the constructor.
and this is my current code giving the error:
import { PaginatedMessage } from '@sapphire/discord.js-utilities';
import { EmbedBuilder } from 'discord.js';

export function movieResponseRebuilder(movieResponse: object) {
console.log('movie Response: ', JSON.stringify(movieResponse));

const display = new PaginatedMessage({
template: new EmbedBuilder().setColor('#8E44AD')
});

movieResponse.forEach((movie) => {
display.addPageEmbed((embed) => {
embed //
.addFields({
name: 'Test Name',
value: 'Test value'
});
return embed;
});
console.log('looped movie data', JSON.stringify(movie));
});

return display;
}
import { PaginatedMessage } from '@sapphire/discord.js-utilities';
import { EmbedBuilder } from 'discord.js';

export function movieResponseRebuilder(movieResponse: object) {
console.log('movie Response: ', JSON.stringify(movieResponse));

const display = new PaginatedMessage({
template: new EmbedBuilder().setColor('#8E44AD')
});

movieResponse.forEach((movie) => {
display.addPageEmbed((embed) => {
embed //
.addFields({
name: 'Test Name',
value: 'Test value'
});
return embed;
});
console.log('looped movie data', JSON.stringify(movie));
});

return display;
}
movieResponse is an array of objects that can exceed 25 objects. how do I get around this error as you can see, I don't have any menus in place in my embed code.
22 replies
SIASapphire - Imagine a framework
Created by Caspian Nightworth on 11/10/2023 in #sapphire-support
ReferenceError: exports is not defined in ES module scope
I am trying to run my bot and am presented with the following error
Successfully compiled: 13 files with swc (25.27ms)
Debugger listening on ws://0.0.0.0:9229/db93ad55-46aa-4ed1-be89-f2b2b5cded3b
For help, see: https://nodejs.org/en/docs/inspector
file:///home/demonicpagan/development/nodejs/discordBots/discord-trakt/dist/bot.js:2
Object.defineProperty(exports, "__esModule", {
^

ReferenceError: exports is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and '/home/demonicpagan/development/nodejs/discordBots/discord-trakt/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
at file:///home/demonicpagan/development/nodejs/discordBots/discord-trakt/dist/bot.js:2:23
at ModuleJob.run (node:internal/modules/esm/module_job:217:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:316:24)
at async loadESM (node:internal/process/esm_loader:34:7)
at async handleMainPromise (node:internal/modules/run_main:66:12)

Node.js v20.9.0
 ELIFECYCLE  Command failed with exit code 1.
Successfully compiled: 13 files with swc (25.27ms)
Debugger listening on ws://0.0.0.0:9229/db93ad55-46aa-4ed1-be89-f2b2b5cded3b
For help, see: https://nodejs.org/en/docs/inspector
file:///home/demonicpagan/development/nodejs/discordBots/discord-trakt/dist/bot.js:2
Object.defineProperty(exports, "__esModule", {
^

ReferenceError: exports is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and '/home/demonicpagan/development/nodejs/discordBots/discord-trakt/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
at file:///home/demonicpagan/development/nodejs/discordBots/discord-trakt/dist/bot.js:2:23
at ModuleJob.run (node:internal/modules/esm/module_job:217:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:316:24)
at async loadESM (node:internal/process/esm_loader:34:7)
at async handleMainPromise (node:internal/modules/run_main:66:12)

Node.js v20.9.0
 ELIFECYCLE  Command failed with exit code 1.
What do I need to do to resolve this? Since there are so many files involved and the length would exceed the Discord limitations, I created a gist with everything I think is needed. https://gist.github.com/dustin-lennon/30bee1b477e4de8dae3459f4fa4c6b96
14 replies
SIASapphire - Imagine a framework
Created by Caspian Nightworth on 10/28/2023 in #sapphire-support
Compiling with SWC
I've been trying to compile my code with SWC and it is finding errors in a couple of my files that were created using the CLI. Those files are src/commands/General/Ping.ts and src/listeners/ready.ts These are the errors that are presented:
> rimraf dist && swc ./src -d dist


× Expression expected
╭─[src/listeners/ready.ts:4:1]
4 │
5 │ const dev = process.env.NODE_ENV !== 'production';
6 │
7 │ @ApplyOptions<Listener.Options>({ once: true })
· ─
8 │ export class UserEvent extends Listener {
9 │ private readonly style = dev ? yellow : blue;
╰────


Caused by:
Syntax Error

× Expression expected
╭─[src/commands/General/Ping.ts:2:1]
2 │ import { isMessageInstance } from '@sapphire/discord.js-utilities';
3 │ import { Command } from '@sapphire/framework';
4 │
5 │ @ApplyOptions<Command.Options>({
· ─
6 │ description: 'Returns the round trip and heartbeat'
7 │ })
8 │ export class UserCommand extends Command {
╰────


Caused by:
Syntax Error
Successfully compiled: 11 files with swc (23.51ms)
Failed to compile 2 files with swc.
Error: Failed to compile:
src/listeners/ready.ts
src/commands/General/Ping.ts
at initialCompilation (/home/demonicpagan/development/nodejs/discordBots/discord-trakt/node_modules/.pnpm/@swc+cli@0.1.62_@swc+core@1.3.95/node_modules/@swc/cli/lib/swc/dir.js:163:19)
at async dir (/home/demonicpagan/development/nodejs/discordBots/discord-trakt/node_modules/.pnpm/@swc+cli@0.1.62_@swc+core@1.3.95/node_modules/@swc/cli/lib/swc/dir.js:228:5)
 ELIFECYCLE  Command failed with exit code 1.
> rimraf dist && swc ./src -d dist


× Expression expected
╭─[src/listeners/ready.ts:4:1]
4 │
5 │ const dev = process.env.NODE_ENV !== 'production';
6 │
7 │ @ApplyOptions<Listener.Options>({ once: true })
· ─
8 │ export class UserEvent extends Listener {
9 │ private readonly style = dev ? yellow : blue;
╰────


Caused by:
Syntax Error

× Expression expected
╭─[src/commands/General/Ping.ts:2:1]
2 │ import { isMessageInstance } from '@sapphire/discord.js-utilities';
3 │ import { Command } from '@sapphire/framework';
4 │
5 │ @ApplyOptions<Command.Options>({
· ─
6 │ description: 'Returns the round trip and heartbeat'
7 │ })
8 │ export class UserCommand extends Command {
╰────


Caused by:
Syntax Error
Successfully compiled: 11 files with swc (23.51ms)
Failed to compile 2 files with swc.
Error: Failed to compile:
src/listeners/ready.ts
src/commands/General/Ping.ts
at initialCompilation (/home/demonicpagan/development/nodejs/discordBots/discord-trakt/node_modules/.pnpm/@swc+cli@0.1.62_@swc+core@1.3.95/node_modules/@swc/cli/lib/swc/dir.js:163:19)
at async dir (/home/demonicpagan/development/nodejs/discordBots/discord-trakt/node_modules/.pnpm/@swc+cli@0.1.62_@swc+core@1.3.95/node_modules/@swc/cli/lib/swc/dir.js:228:5)
 ELIFECYCLE  Command failed with exit code 1.
This is my config for SWC, .swcrc
{
"env": {
"target": {
"node": 20
}
},
"jsc": {
"parser": {
"syntax": "typescript"
}
},
"module": {
"type": "commonjs"
},
"sourceMaps": "inline"
}
{
"env": {
"target": {
"node": 20
}
},
"jsc": {
"parser": {
"syntax": "typescript"
}
},
"module": {
"type": "commonjs"
},
"sourceMaps": "inline"
}
4 replies
SIASapphire - Imagine a framework
Created by Caspian Nightworth on 3/2/2023 in #sapphire-support
ReferenceError: [ENV] BOT_OWNER_IDS - The key must be an array, but is empty or undefined.
I am using @skyra/env-utilities and when I start up my bot, I get the error reported in the title of this post. I cannot figure out what I am missing. I have a .env.local file in my src directory. It is erroring when it gets to export const OWNERS = envParseArray('BOT_OWNER_IDS'); in my src/lib/constants.ts file. This is the contents of my src/lib/setup.ts file:
// Unless explicitly defined, set NODE_ENV as development:
// process.env.NODE_ENV ??= 'development';

import '@sapphire/plugin-api/register';
import '@sapphire/plugin-editable-commands/register';
import '@sapphire/plugin-logger/register';
import * as colorette from 'colorette';
import { type NumberString, setup, type ArrayString } from '@skyra/env-utilities';
import { join } from 'node:path';
import { inspect } from 'util';
import { rootFolder } from './constants';

// Read env var
setup(join(rootFolder, 'src', '.env'));

// Set default inspection depth
inspect.defaultOptions.depth = 1;

// Enable colorette
colorette.createColors({ useColor: true });

declare module '@skyra/env-utilities' {
interface Env {
BOT_OWNER_IDS: ArrayString;
BOT_REPORT_CHANNEL_ID: string;
MONGO_HOST: string;
MONGO_USERNAME: string;
MONGO_PASSWORD: string;
MONGO_DB: string;
MONGO_API_KEY: string;
MONGO_DB_MAX_SIZE: NumberString;
AWS_S3_BUCKET: string;
AWS_REGION: string;
}
}
// Unless explicitly defined, set NODE_ENV as development:
// process.env.NODE_ENV ??= 'development';

import '@sapphire/plugin-api/register';
import '@sapphire/plugin-editable-commands/register';
import '@sapphire/plugin-logger/register';
import * as colorette from 'colorette';
import { type NumberString, setup, type ArrayString } from '@skyra/env-utilities';
import { join } from 'node:path';
import { inspect } from 'util';
import { rootFolder } from './constants';

// Read env var
setup(join(rootFolder, 'src', '.env'));

// Set default inspection depth
inspect.defaultOptions.depth = 1;

// Enable colorette
colorette.createColors({ useColor: true });

declare module '@skyra/env-utilities' {
interface Env {
BOT_OWNER_IDS: ArrayString;
BOT_REPORT_CHANNEL_ID: string;
MONGO_HOST: string;
MONGO_USERNAME: string;
MONGO_PASSWORD: string;
MONGO_DB: string;
MONGO_API_KEY: string;
MONGO_DB_MAX_SIZE: NumberString;
AWS_S3_BUCKET: string;
AWS_REGION: string;
}
}
contents of my .env.local:
NODE_ENV=development

# Tokens
DISCORD_TOKEN=discordToken
DISCORD_CLIENT_ID=11111111
DISCORD_CLIENT_SECRET=discordSecret
DISCORD_PUBLIC_KEY=discordPubKey

# Configuration
DEFAULT_PREFIX=dmb
BOT_OWNER_IDS='49242868987990016 253018958536376321'
BOT_REPORT_CHANNEL_ID=470100327840874496

# Mongo DB Data
MONGO_HOST=some.address.mongodb.net
MONGO_USERNAME=username
MONGO_PASSWORD=password
MONGO_DB=db
MONGO_API_KEY=apiKey
MONGO_DB_MAX_SIZE=496

# AWS S3 Data
AWS_REGION=us-east-2
AWS_ACCESS_KEY_ID=awsAccessKey
AWS_SECRET_ACCESS_KEY=awsSecret
AWS_S3_BUCKET=awsBucket
NODE_ENV=development

# Tokens
DISCORD_TOKEN=discordToken
DISCORD_CLIENT_ID=11111111
DISCORD_CLIENT_SECRET=discordSecret
DISCORD_PUBLIC_KEY=discordPubKey

# Configuration
DEFAULT_PREFIX=dmb
BOT_OWNER_IDS='49242868987990016 253018958536376321'
BOT_REPORT_CHANNEL_ID=470100327840874496

# Mongo DB Data
MONGO_HOST=some.address.mongodb.net
MONGO_USERNAME=username
MONGO_PASSWORD=password
MONGO_DB=db
MONGO_API_KEY=apiKey
MONGO_DB_MAX_SIZE=496

# AWS S3 Data
AWS_REGION=us-east-2
AWS_ACCESS_KEY_ID=awsAccessKey
AWS_SECRET_ACCESS_KEY=awsSecret
AWS_S3_BUCKET=awsBucket
I am not sure what I am missing or how to resolve
13 replies
SIASapphire - Imagine a framework
Created by Caspian Nightworth on 3/1/2023 in #sapphire-support
How to use `@sapphire/shapeshift ` dateValid & stringRegex
I have a slash command that needs to take in a date input in the format of YYYY-MM-DD. I want to perform validation on this and throw an error if it is not in this format or not a valid date. I was looking at the documenation, but I was hoping to see a code example to help explain the usage. I appreciate the explanation and help.
4 replies
SIASapphire - Imagine a framework
Created by Caspian Nightworth on 2/25/2023 in #sapphire-support
How to get the current channel a slash command was used in
I took a look at the following post https://discord.com/channels/737141877803057244/1061609301556346921 and
const target= await interaction.guild?.channels.cache.get('id');
const target= await interaction.guild?.channels.cache.get('id');
comes up as undefined. I am needing to get returned as if I were running client.channels.fetch(process.env.BOT_REPORT_CHANNEL_ID)
4 replies