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/nodepnpm init
pnpm i @splitscript.js/discord dotenv
pnpm i -g @splitscript.js/core@latest
pnpm i --save-dev @types/nodebun init
bun i @splitscript.js/discord dotenv
bun i -g @splitscript.js/core@latest
bun i --save-dev @types/nodeConnect to Discord
Creating a bot
Go to https://discord.com/developers/applications
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
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
This section requires the applications.commands scope
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?







