Skip to Content
nyx logonyx guide

Start

Getting started with nyx

Reading time:3 min read

First Start

A minimum version of Node.js 18 is required to run, though we recommend latest LTS. Although they should work, nyx is not tested on other runtimes, such as Deno or Bun.

We also recommend using a formatter like Prettier and a linter like ESLint or TypeScript ESLint.

Installing

npm i @nyx-discord/djs discord.js

Creating a Client

You'll need a client, which will depend on the adapter you're using. It can be any client, as long as it's not logged in or destroyed.

import { ,  } from 'discord.js';

const  = new ({ : [.] });

Creating a Bot

Next up, we'll create a new instance of Bot. This is the main entry point of the framework, and it will handle the lifecycle of your bot, including loading commands, managing events, and more.

There's no global state, so you can create multiple bots and they'll all work independently with no issues!

Create one with Bot.create(), which takes a function that gets passed the currently constructing bot instance, and should return the options that you want for the bot.

import { , type  } from '@nyx-discord/djs';

const  = .((: ) => ({
  : 'TOKEN',
  ,
  : , // Can be your own logger, see the NyxLogger docs
  : true, // Whether to deploy commands to Discord on start
}));

Starting the Bot

Finally, to start it, simply call .start(). This will log in the client, set up event listeners, and get everything ready:

await .();

If the start errors, it'll reject the promise, and the bot will enter in a BotStatusEnum.Killed state, meaning it won't be able to be used anymore. You can create a new bot instance and start it again, but you cannot recover the previous one.

To get a bot's status at any time, you can use Bot#getStatus().

Next Steps

Click on each card to learn more about that feature.
Edit on GitHub

Last updated on

On this page