NewSchokr 13 is here. A whole new UI, seven locations, snapshots and more. Read more →

How to run a Discord bot with Bun on Schokr

Host a discord.js bot with the Bun runtime on Schokr: run TypeScript without a build step, use Bun's built-in .env loading and install with bun install.

Updated · 2 min read

Schokr has a Bun template, so you can run a JavaScript or TypeScript Discord bot with Bun instead of Node.js. Bun runs .ts files directly and loads .env files automatically, which makes small bots simpler to set up.

Why use Bun for a bot?

FeatureBunNode.js
Run TypeScriptDirectly, no build stepNeeds a build (or a loader)
Load .envAutomaticNeeds dotenv or --env-file
Install packagesbun installnpm install
Built-in SQLitebun:sqliteThird-party package or newer Node versions

Most pure JavaScript packages, including discord.js, work on Bun. Packages with native add-ons or voice support may behave differently, so test locally first. If something misbehaves, the Node.js template is the safe fallback.

1. Set up the project locally

mkdir my-bot
cd my-bot
bun init -y
bun add discord.js

2. Write index.ts

import { Client, Events, GatewayIntentBits } from 'discord.js';

const client = new Client({ intents: [GatewayIntentBits.Guilds] });

client.once(Events.ClientReady, (c) => {
  console.log(`Logged in as ${c.user.tag}`);
});

client.on(Events.InteractionCreate, async (interaction) => {
  if (!interaction.isChatInputCommand()) return;
  if (interaction.commandName === 'ping') {
    await interaction.reply('Pong from Bun!');
  }
});

client.login(Bun.env.DISCORD_TOKEN);

Create .env next to it:

DISCORD_TOKEN=your-token-here

Bun reads .env on its own, so you don't need the dotenv package. process.env.DISCORD_TOKEN works too.

The /ping command must be registered before it appears in Discord. See slash commands in discord.js.

3. Add a start script

{
  "name": "my-bot",
  "module": "index.ts",
  "type": "module",
  "scripts": {
    "start": "bun run index.ts"
  },
  "dependencies": {
    "discord.js": "^14.16.0"
  }
}

Run bun start locally and confirm the bot logs in.

4. Deploy to Schokr

  1. Create a server from the Bun template in the Schokr console.
  2. Upload index.ts, package.json, your lockfile and any other source folders with the file manager. Skip node_modules.
  3. Create .env in the server root with your token.
  4. In your server's Startup settings, set the main file or startup command to your entry point, for example index.ts.
  5. Start the server. Dependencies from package.json are installed, then your bot starts. Watch the console for the "Logged in" line.

Troubleshooting

  • "Cannot find package": the package isn't in package.json. Add it locally with bun add, upload the new package.json and restart.
  • Token is undefined: .env must be in the folder Bun runs from (the server root) and the variable name must match exactly.
  • A package works on Node but not Bun: check the package's issues and Bun's compatibility notes on bun.sh, or switch to the Node.js template.