Skip to main content

Getting started with Sapphire

To install Sapphire, you need to install both discord.js and @sapphire/framework. You can do this by running the following command:

npm install @sapphire/framework discord.js

You need at least Node.js version 16.6.0 to use Sapphire.


When using Sapphire, it is important that you set a main property in your package.json. This is used to determine where we will need to look for your commands, listeners, and other pieces. If you don't set this property, we will not be able to automatically find your bot's pieces.

You should set this property to the main file of your project; where you call client.login(). For example, if your client.login() is located at src/index.js, then you should set your main to src/index.js.

Here is an example of a package.json file:

"name": "my-awesome-new-bot",
"main": "src/index.js",
"dependencies": {
"@sapphire/framework": "latest",
"discord.js": "latest"
"scripts": {
"start": "node src/index.js"

Creating an index.js file

While it doesn't have to be called index.js, this file will be the main file for your bot (otherwise known as the entry point) as it'll handle the bot's setup and login. It's recommended to put this inside a subdirectory of your project, typically src, both for organization and for Creating Commands.

To begin, import @sapphire/framework and instantiate SapphireClient. This is where you can customize Sapphire's and discord.js' behaviour. Sapphire's client extends discord.js', so everything from Client is available in SapphireClient!

import { SapphireClient } from '@sapphire/framework';

const client = new SapphireClient({ intents: ['GUILDS', 'GUILD_MESSAGES'] });


Sapphire detects mention prefixes (@bot command), but you can optionally define any number of default prefixes with the defaultPrefix option and regexPrefix for more complex cases.

There is also the advanced option baseUserDirectory, which allows you to define the base directory Sapphire will scan. By default, Sapphire registers this as the directory containing your entry point and locates stores within it. As such, if the root directory is src, it will register src/commands as one of the command directories.


You should use environment variables or a config.json for your token instead of passing it directly! You can read more about why you should here.

And that's it for your index.js file! In the end, your directory should look like this, along with whatever .gitignore or config.json files you may have:

├── node_modules
├── package.json
└── src
└── index.js