Skip to main content

Cordeno

Cordeno

deno doc GitHub stars Discord GitHub last commit
An simplistic, event loop driven Discord API library for building powerful bots.
Powered by the Deno runtime.
Inspired by Dinocord.

Development progress

Cordeno is still in its early stages of development, and is not production ready. Many cores features of the Discord API is still missing, and has yet to be implemented. Breaking changes may occur at any time without prior warning.
Current master branch version: 0.2.2
Find dev branch here!

Example:

index.ts

import { Client, Message, Ready, Ratelimit, Heartbeat } from "https://deno.land/x/cordeno@v0.2.2/mod.ts";

const client = new Client({
  token: "YOUR TOKEN HERE",
});

console.log(`Running cordeno v${client.version}`);

for await (const ctx of client) {
  switch (ctx.event) {
    case "READY": {
      const ready: Ready = ctx;

      console.log("Cordeno is now ready!");
      console.log("Discord websocket API version is " + ready.gatewayVersion);
      break;
    }
    case "RATELIMIT": {
      const ratelimit: Ratelimit = ctx;
      console.log(`A rate limit was hit for the route: ${ratelimit.route}`);
      // deno-fmt-ignore
      console.log(`The ratelimit will reset in ${Math.round(ratelimit.resetIn / 1000 * 10) / 10}s`);
      break;
    }

    case "HEARTBEAT": {
      const heartbeat: Heartbeat = ctx;
      // deno-fmt-ignore
      console.log(
        "Heartbeat recieved: \n" +
        `=>total: ${heartbeat.total}\n=>rate: ${Math.round(heartbeat.rate / 1000 * 10) / 10}s`
        );
      break;
    }
    case "MESSAGE_CREATE": {
      const msg: Message = ctx;

      if (msg.author.id !== client.user.id) {
        if (msg.content === "!ping") {
          await msg.reply(`Pong!`);
          await msg.reply(`Message author: ${msg.author.username}`);
          await msg.reply(`Created at: ${msg.createdAt}`);
          continue;
        }
        if (msg.content === "!cordeno") {
          await msg.reply(`Cordeno version: v${client.version}`);
        }
      }
      break;
    }
  }
}

After creating your file and pasting the above code, add your token and run

deno run --allow-net --reload index.ts

The --reload tag reinstalls all the dependencies in your project. You don’t have to include --reload every run, but I recommend including it as an argument at least once a day to keep cordeno up to date.

Contributing

GitHub contributors
Want to contribute? Follow the Contributing Guide