Skip to main content
Deno 2 is finally here 🎉️
Learn more

Core middleware to use with denska.

denska-core is a set of middleware functions, interfaces, classes; and more which help when using denska. This is an official middleware library for denska and should always be kept up-to-date.

Just getting started

If you’d like to see everyting that [desnka-core] offeres, please look at the docs.

In the denska example we went over sending the identify payload after receiving the hello payload. In the super quick example, we’ll look at doing that along with heartbeating with [desnka-core].

First let’s get everything we need from denska and denska-core and then create a Shard. We’ll go over everything when we use it.

import { Shard } from "https://deno.land/x/denska/mod.ts";
import { identify, heartbeat, Intent } from "https://deno.land/x/denska_core/mod.ts";

const shard = new Shard({ url: "wss://gateway.discord.gg" });

A Shard is a single instance of a connection to the @discord gateway. We may later want to create multiple Shards to handle more data over separate instances.

Next we’ll use the identify middleware to handle sending the identify payload when we receive the hello payload.

shard.use(identify(shard, {
  token: "<bot_token>",
  intents: [Intent.GUILD_MESSAGES]
}));

As you can see this a lot more simple than what we did before in the denska example. Intents decide what our bot is allowed to access event wise.

As an extra bonus we can also setup heartbeating which allows our bot to continue running.

shard.use(heartbeat(shard));

This one was even more simpler than identify. This will do all the work in the background to keep your bot running.

We’ll also console.log the ctx to see what we get.

shard.use(async (ctx, next) => {
  console.log(ctx);
});

You’ll see the same output as in the denska example, but you’ll also see the heartbeatack payload every so often.

{ raw: { t: null, s: null, op: 11, d: null } }