Creating a Spark Bot
Installation
CLI Installation
Spark now has a CLI which you can use to boostrap your project with all of the things you need to create a Spark bot.
To install the CLI, you need to run the create-spark
npm package.
npm create spark
yarn create spark
pnpm create spark
After you run this, you'll see the list of commands. Run the previous command you did with init
at the end to initialize a Spark bot.
You will be asked a few questions regarding your bot. If you'd like to skip this, you can pass the -y
flag to use the default settings.
Manual Installation
To create a new Spark project, install the @spark.ts/handler
package.
npm i @spark.ts/handler
yarn add @spark.ts/handler
pnpm add @spark.ts/handler
Setup
In your main file, create a client
variable.
Inside of the client declaration, you can put the following options:
export interface SparkClientOptions {
/**
* Directories used by the client.
* If you're using TypeScript, point this to your `dist` folder directories!
*/
directories?: {
events?: string;
commands?: string;
};
/**
* The log level for the logger
*/
logLevel?: 'Debug' | 'Info' | 'Warn' | 'Error' | 'Success';
/**
* The prefix used for text commands
*/
prefix?: string;
}
You can also put options from the Discord.js ClientOptions
.
TypeScript & ESM
import { SparkClient } from '@spark.ts/handler';
export const client = new SparkClient({
intents: ['Guilds', 'GuildMessages'],
// If you're using TS, use your dist folder.
directories: {
events: './dist/events',
commands: './src/commands',
},
});
CommonJS
const { SparkClient } = require('@spark.ts/handler');
const client = new SparkClient({
intents: ['Guilds', 'GuildMessages'],
// Default directories, you can remove this option if you're using these.
directories: {
events: './src/events',
commands: './src/commands',
},
});
module.exports = client;
Starting Your Bot
With Spark, all you have to do is client.login(token)
.
This initializes all of your commands, events, and pre-process plugins (if applicable).