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
Example
const client = new SapphireClient({
presence: {
activity: {
name: 'for commands!',
type: 'LISTENING'
}
}
});
client.login(process.env.DISCORD_TOKEN)
.catch(console.error);
Example
// 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...
});
Example
// Opt-out automatic scanning:
const client = new SapphireClient({
baseUserDirectory: null,
// More options...
});
Type parameters
Name | Type |
---|---|
Ready | extends boolean = boolean |
Hierarchy
-
Client
<Ready
>↳
SapphireClient
Constructors
constructor
• new SapphireClient<Ready
>(options
): SapphireClient
<Ready
>
Type parameters
Name | Type |
---|---|
Ready | extends boolean = boolean |
Parameters
Name | Type |
---|---|
options | ClientOptions |
Returns
SapphireClient
<Ready
>
Overrides
Client<Ready>.constructor
Defined in
projects/framework/src/lib/SapphireClient.ts:280
Properties
application
• application: If
<Ready
, ClientApplication
, null
>
Inherited from
Client.application
Defined in
node_modules/discord.js/typings/index.d.ts:971
channels
• channels: ChannelManager
Inherited from
Client.channels
Defined in
node_modules/discord.js/typings/index.d.ts:972
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
Example
// Return always the same prefix (unconfigurable):
client.fetchPrefix = () => '!';
Example
// 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 ?? '!';
};
Example
// 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
guilds
• guilds: GuildManager
Inherited from
Client.guilds
Defined in
node_modules/discord.js/typings/index.d.ts:974
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