create your first project

Install Dependencies

npm init -y

npm i @splitscript.js/discord dotenv
npm i -g @splitscript.js/core@latest

npm i --save-dev @types/node

Connect to Discord

Creating a bot

Go to https://discord.com/developers/applications

Create a bot

Click "New Application"

Enter a name and click "Create"

Click "Reset Token"

Click Copy

Invite your bot

Click "Installation"

Select "Discord Provided Link"

Add "bot" scope and "Administrator" permissions

Open the install link

Create an env file

Import environment variables

In your editor of choice, create a app.ts file

Start listening

Get your bot online

You can now start the bot, by running

This command also provides boilerplate for listeners and automatic restarts when you save a file

Run code on start

You can run a function after the bot starts, by using the ready event

After saving this, look at your terminal. It should show the above message

Add a message (prefix) command

Enable Message Content Intent

We need to set the intent in our code to be able to read messages

Next, lets handle the command. We'll use the discord/message/create event

Now, when you send a message starting with !ping, our bot responds with Pong!

Slash Commands

Register the Command

Before we can handle commands, we need to register it first. Lets do this automatically in our functions/discord/ready folder.

It may take a few minutes for the command to appear

Handle the Command

After runnning /ping, our bot should reply with Pong!

Last updated

Was this helpful?