Contact me

How to create a discord bot with eris and typescript

Go to discord developer portal and click new application. After you created a new application go to bot. bot Copy your bot’s token and save it somewhere. Selects intents you want to use. intents

Go to OAuth2 then go to url generator, select bot and application.commands. Select bot permissions.urlOpen the url that was generated select the server you want to add your bot to. server

Code

If you want to use typescript you need to install nodejs. After you installed nodejs you need to install typescript and eris.

npm install -D typescript
npm install -D ts-node
npm install @types/node
npm install eris

after you have installed typescript and eris you can create index.ts file and import eris.

// index.ts
import Eris from "eris";
const bot = new Eris.Client("BOT_TOKEN", {
  intents: ["guildMessages"],
});
bot.on("ready", () => {
  console.log("Ready!");
});

bot.on(‘createmessage’) is an event that is called every time a new message is sent. The bot checks if the message is equal to ‘!ping’ if it is it send a message ‘Pong!’.

bot.on("messageCreate", (msg) => {
  if (msg.content === "!ping") {
    bot.createMessage(msg.channel.id, "Pong!");
  }
});
bot.connect();

run index.ts using ts-node

ts-node index.ts

Send !ping to your server. ping