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

Denska-core is the official core middleware library for denska.

This provides middleware for some of the simpler, repetitive things such as identifying and heartbeating that you’d setup for every project.

The denska example using denska-core.

This will go through the same process as the denska example, however, we’ll be using the middleware in denska-core to do the work.

Setting up.

First things first - once again - let’s get everything that we need setup. This includes importing stuff and creating a shard.

// in your code you'll want to specify versions for both of these
import { Shard, Opcode } from "https://deno.land/x/denska";
import { identify, heartbeat } from "https://deno.land/x/denska_core";

// this isn't the best way to do it, you'd want to get this beforehand
const shard = new Shard({
    url: "wss://gateway.discord.gg/?v=8&encoding"
});

// this is just so that we can access it easier later
const Intent = identify.Intent;

Nice, now we’ve setup the base we can get into creating using some middleware!

Identifying.

This is an important step as it let’s us receive events for our bot going forward.

// this will do our identifying
shard.use(identify(shard, {
    token: "<bot_token>",
    // we want guild and guild message events
    intents: [Intent.GUILD_MESSAGES, Intent.GUILD]
}));

Here we just pass in the bot’s token and the intents for the events we want to receive. We also pass in shard so that it can send the needed payloads.

Heartbeating.

This is an important step as it let’s us receive events for our bot going forward.

// this will do our heartbeating
shard.use(heartbeat(shard));

Once again we also pass in shard so that it can send the needed payloads. Yep, that’s it for the heartbeating setup, super simple stuff.

Testing.

To see the results look at the testing section in denska.