OmgImAlexis / discord.ts-example

Discordx starter bot example

Home Page:https://discord-ts.js.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Discord server NPM version NPM downloads Build status paypal

Create a discord bot with TypeScript and Decorators!

Content

Demo

CodeSandbox

Installation

Clone Repository

git clone https://github.com/oceanroleplay/discord.ts-example

Enter bot directory

cd discord.ts-example

Install Dependencies

npm install

Build your bot

npm run build

Set your bot token

For windows user only

# For command prompt
set BOT_TOKEN=REPLACE_THIS_WITH_YOUR_TOKEN

# For powershell
$env:BOT_TOKEN = "REPLACE_THIS_WITH_YOUR_TOKEN"

For linux user only

export BOT_TOKEN=REPLACE_THIS_WITH_YOUR_TOKEN

Start your bot

npm run serve

you are done, you will see your bot up and running. For detailed installation guide, please see this

Use global command only

This repository uses guild commands instead of global commands by default. This is because global command needs approximately 15 minutes to update itself every time.

1. How do I use global command only?

2. How do I make specific guild command?

Use CommonJS

This repo is targed to use ECMAScript modules by default. Follow these steps to use CommonJS.

Update package.json

{
  // ...
  "type": "commonjs",
  // ...
  "scripts": {
    "build": "tsc",
    "dev": "ts-node src/main.ts",
    "start": "nodemon --exec ts-node src/main.ts",
    "serve": "node build/main.js"
  }
  // ...
}

Update tsconfig.json

{
  "compilerOptions": {
    "target": "ESNext",
    "module": "CommonJS"
    // ...
  }
}

Update main.ts

async function run() {
  // with cjs
  await importx(__dirname + "/{events,commands}/**/*.{ts,js}");
  // with ems
  // await importx(dirname(import.meta.url) + "/{events,commands}/**/*.{ts,js}");
  client.login(process.env.BOT_TOKEN ?? ""); // provide your bot token
}

Remove rest api server

There are only a few lines of basic code, which you need to either comment out or remove to disable the API server

  1. Delete the api folder from the src folder
  2. Remove api reference from importx path in main.ts#L57
  3. Comment out or remove the code from main.ts#L5 and main.ts#L66 - main.ts#L81
  4. Run npm uninstall koa @koa/router @discordx/koa @types/koa @types/koa__router

The API server has been removed from the discord bot

☎️ Need help?

Ask in discord server or open a issue

Thank you

Show your support for discordx by giving us a star on github.

About

Discordx starter bot example

https://discord-ts.js.org


Languages

Language:TypeScript 97.9%Language:Dockerfile 2.1%