Class: SapphireClient<Ready>
The base Client extension that makes Sapphire work. When building a Discord bot with the framework, the developer must either use this class, or extend it.
Sapphire also automatically detects the folders to scan for pieces, please read StoreRegistry.registerPath for reference. This method is called at the start of the SapphireClient.login method.
See
SapphireClientOptions for all options available to the Sapphire Client. You can also provide all of discord.js' ClientOptions
Since
1.0.0
Examples
const client = new SapphireClient({
presence: {
activity: {
name: 'for commands!',
type: 'LISTENING'
}
}
});
client.login(process.env.DISCORD_TOKEN)
.catch(console.error);
// Automatically scan from a specific directory, e.g. the main
// file is at `/home/me/bot/index.js` and all your pieces are at
// `/home/me/bot/pieces` (e.g. `/home/me/bot/pieces/commands/MyCommand.js`):
const client = new SapphireClient({
baseUserDirectory: join(__dirname, 'pieces'),
// More options...
});
// Opt-out automatic scanning:
const client = new SapphireClient({
baseUserDirectory: null,
// More options...
});
Extends
Client
<Ready
>
Type Parameters
Type Parameter | Default type |
---|---|
Ready extends boolean | boolean |
Constructors
new SapphireClient()
new SapphireClient<
Ready
>(options
:ClientOptions
):SapphireClient
<Ready
>
Parameters
Parameter | Type |
---|---|
options | ClientOptions |
Returns
SapphireClient
<Ready
>
Overrides
Client<Ready>.constructor
Defined in
projects/framework/src/lib/SapphireClient.ts:280
Properties
disableMentionPrefix?
optional
disableMentionPrefix:boolean
Whether the bot has mention as a prefix disabled
Default
false
Example
client.disableMentionPrefix = false;
Defined in
projects/framework/src/lib/SapphireClient.ts:272
fetchPrefix
fetchPrefix:
SapphirePrefixHook
The method to be overridden by the developer.
Since
1.0.0
Returns
A string for a single prefix, an array of strings for matching multiple, or null for no match (mention prefix only).
Examples
// Return always the same prefix (unconfigurable):
client.fetchPrefix = () => '!';
// Retrieving the prefix from a SQL database:
client.fetchPrefix = async (message) => {
// note: driver is something generic and depends on how you connect to your database
const guild = await driver.getOne('SELECT prefix FROM public.guild WHERE id = $1', [message.guild.id]);
return guild?.prefix ?? '!';
};
// Retrieving the prefix from an ORM:
client.fetchPrefix = async (message) => {
// note: driver is something generic and depends on how you connect to your database
const guild = await driver.getRepository(GuildEntity).findOne({ id: message.guild.id });
return guild?.prefix ?? '!';
};
Overrides
Client.fetchPrefix
Defined in
projects/framework/src/lib/SapphireClient.ts:255
id
id:
null
|string
=null
The client's ID, used for the user prefix.
Since
1.0.0
Overrides
Client.id
Defined in
projects/framework/src/lib/SapphireClient.ts:225
logger
logger:
ILogger
The logger to be used by the framework and plugins. By default, a Logger instance is used, which emits the messages to the console.
Since
1.0.0
Overrides
Client.logger
Defined in
projects/framework/src/lib/SapphireClient.ts:262
stores
stores:
StoreRegistry
The registered stores.
Since
1.0.0
Overrides
Client.stores
Defined in
projects/framework/src/lib/SapphireClient.ts:278
plugins
static
plugins:PluginManager
Defined in
projects/framework/src/lib/SapphireClient.ts:364
Methods
login()
login(
token
?:string
):Promise
<string
>
Loads all pieces, then logs the client in, establishing a websocket connection to Discord.
Parameters
Parameter | Type | Description |
---|---|---|
token ? | string | Token of the account to log in with. |
Returns
Promise
<string
>
Token of the account used.
Since
1.0.0
Overrides
Client.login
Defined in
projects/framework/src/lib/SapphireClient.ts:339
use()
static
use(plugin
: typeofPlugin
): typeofSapphireClient
Parameters
Parameter | Type |
---|---|
plugin | typeof Plugin |
Returns
typeof SapphireClient