Sapphire - Imagine a framework

SIA

Sapphire - Imagine a framework

Welcome to the Sapphire Discord server! The next-gen object-oriented Discord.js bot framework can be found here.

Join

sapphire-support

discordjs-support

old-sapphire-support

old-discordjs-support

old-application-commands-and-interactions

Run bot without building to js and use ts-node or other alternatives instead.

Is there a way to achieve the title? Currently I need to build and then run the js file using the command:
npm run build && npm run start
npm run build && npm run start
...
Solution:
If you want to test the bot, then tsc-watch is good. Or you can remove typescript & code directly in js Or you can use bun runtime to start your typescript based bot directly (you will need to refactor your code so that it runs on bun)...

Unregister Old Application Sub Commands from the subcommands plugin

Some old commands i have made still appear in the autofill when typing a application command, how would i get rid of those?
Solution:
If they are still registered either use bulk overwrite by sapphire, use the discordjs methods to unregister, or use https://slash-commands-gui.androz2091.fr

Application Commands are not being registered when bot restarts.

I have an auto-update mechanism built into my bot so I don't have to reupload to the host every time I push a new build, and it appears that whenever the app restarts (using process.exit() and then Pterodactyl starts it back up), my application commands are not re-registered. There is no error in console indicating an issue and restarting forcefully (using Restart button in Pterodactyl) does not cause the issue to occur. Would anyone have some pointers for me to help figure out why this is hap...

Cannot set properties of undefined when extending `container`

Hello! I wanted to create a property entities that holds two properties which would be users and guild of class Entity. Now entities doesn't have any type at all since it'll just be an object to hold users and guild in one. But whenever I run my bot I receive Cannot set properties of undefined (setting 'users') Here's my augments: ```ts declare module '@sapphire/pieces' {...
Solution:
You need to assign .entities, like this:
container.entities = {
users: new Entity({}),
guilds: new Entity({})
};
container.entities = {
users: new Entity({}),
guilds: new Entity({})
};
...

Bot freezing after evaluate `.client`

- evaluated how eval this.container.client - with which options option? - define "hang"...

will using super while having @ApplyOptions work

will this code still work? will @applyoptions be applied or no
Solution:
no, it's either constructor or applyoptions. Just default guildId to empty string on line 24?
No description

Command.LoaderContext does not exist

I have been updating my code to the new versions recently released, and Command.Context has been deprecated, but Command.LoaderContext does not exist. Listener.LoaderContext does exist however. "@sapphire/framework": "^4.8.2",...
Solution:
Mb, Command is from @kaname-png/plugin-subcommands-advanced (which probably hasn't been updated yet), not sapphire

found differences for command when i havent made any changes

not sure whats happening but i havent made any changes and it still says its finding differences
Solution:
@iaqi replace your gear emote
No description

Can't create new listener

I've tried to create a ready listener as the getting started shows, but it crashes
Solution:
exact same error as #TypeError Class constructor _SapphireClient cannot be invoked without 'new' This means your target wasn't set so it defaults to ES3 which is ancient JS that isn't supported and doesn't supported classes...

@sapphire/shapeshift validate env library

How would I go about making a library which validates the process.env similar to that of znv but using @sapphire/shapeshift. Was thinking of doing that so I keep my libraries within sapphire if possible

Extending the container wont work?

Maybe my enviroment is wrong? I restarted the ts client*...
Solution:
WAIT solved i didnt have sapphire/pieces installed, (i usually have it so i didnt check)
No description

Listeners and Handlers not registering interactions/events

Hey! After the latest release my bot is not responding to any interactions or events. Slash commands, buttons, modals, everything stopped working. I already made the necessary changes to my files...
Solution:
This really is just a duplicate of #Deployment failing, we haven't fully finished rolling out all updates yet. Afterwards please start anew.

Deployment failing

Hey! My sapphire deployment is failing but I don't really know why. It is giving me some errors on the framework's code apparently: ``` ...
Solution:
Not a Sapphire bug, but rather a semi-breaking type change in latest version that we're announcing in a few minutes. tl;dr: You need to use InteractionHandler.LoaderContext instead of PieceContext. Likewise for commands it's Command.LoaderContext, listeners Listener.LoaderContext, and so on....

Log File

Is there an setting that i can change so my bot saves logs to a file?
Solution:
You'll have to create your own logger plugin for that. However it should be noted that if you host your bot with something like pm2 or docker that those services already create a log file of themselves so creating one of your own means you're duplicating all the logging.

Pre-built binaries not installable for @sapphire/[email protected] & build failing

Hi, I'm opening this thread for a contributor who is encountering issues attempting to install Sapphire The full logs are found at: https://gist.github.com/Southpaw1496/21a4679c77a48baa063aad67680443d4 A highlight is that │ node-pre-gyp http GET https://github.com/sapphiredev/type/releases/download/v2.4.0/type-v2.4.0-node-v108-darwin-arm64-unknown-unknown.tar.gz the build step seems to not be able to resolve the last two parts of their machine information...
Solution:
Make sure you are up-to-date using the latest @sapphire/type. Python 3.12 broke some stuff in node-gyp but that’s been fixed in @sapphire/type 3.4.1. Also make that your lock file is regerenated and only pulls in node-gyp v10 or higher (the transitive dependency should be node-gyp@latest).

Any idea why is this happening?

I updated the packages and the types got messed up
Solution:
Remove @sapphire/pieces from your dependencies and just let it be pulled in as a transitive dependency.

Autocomplete within command class

iya, I was wondering if there's a way to add an autocomplete handler within the command class, so i dont have to create my own autocomplete handler. I'm using @sapphire/plugin-subcommands so wondering if theres something like that so I could just specify autocomplete: besides chatInputRun: or something...

Paginated message support

Can i allow paginated message actions to be controlled by anyone in server, currently it accepts an argument of whom to give.
await paginatedMessage.run(msg, msg.author);
await paginatedMessage.run(msg, msg.author);
...
Solution:
There is no such option and it likely wont be added because target isn't just used for filtering interactions but also internationalisation and ensuring interactions stay in sync.

Subcommand wont get registered

Hey, I know it must be some little stupid thing I did wrong: Im trying to create subcommands but while starting my bot I get the following error: TypeError: Cannot read properties of undefined (reading 'parseConstructorPreConditionsRunIn') ...
Solution:
Update your dependencies, framework specifically. The method is a static method on Command class.
No description

Permission bits to Human Readable text

Is it possible to get Human readable text from permission bits? I'm trying to make a help command which extracts command names via container stores & when user selects the command name, the help command then extracts detailedDescription of selected command to show. A nice addition would be to show the permissions required....
Solution:
const { PermissionsBitField } = await import('discord.js');

new PermissionsBitField(the bits here).toArray()
const { PermissionsBitField } = await import('discord.js');

new PermissionsBitField(the bits here).toArray()
...