0.43.6 • Published 12 months ago

droff v0.43.6

Weekly downloads
-
License
MIT
Repository
-
Last release
12 months ago

Discord

Simple Discord client powered by RxJS and Axios

Note: Looking for a Discord library that is more functional in nature?
Check out: https://github.com/tim-smart/dfx

Goals

  • Lightweight - Simple Axios wrapper for the REST API with a lean Gateway API wrapper powered by RxJS.
  • Functional - Favour functional composition over inheritence.
  • Scalable - Every component of the library can be scaled seperately, allowing for easy horizontal distribution of your bot.

Packages

NameDescription
droffThe core Discord client library
droff-interactionsAccompanying library for interaction based components (slash commands, buttons, menus, selects etc)
droff-commandsAccompanying library to help implementing message based commands
droff-helpersA collection of helper functions to make using droff easier
droff-redisAn implementation of a Redis powered gateway proxy, cache store and rate limit store

Install

yarn add droff

Usage

Basic ping example. Look at droff-interactions and droff-commands for examples that work with slash commands etc.

Please note that you have to subscribe to client.effects$ for the client to function. This essentially starts the client.

import { createClient, Intents } from "droff";
import * as Rx from "rxjs";
import * as RxO from "rxjs/operators";

const client = createClient({
  token: process.env.DISCORD_BOT_TOKEN!,
  gateway: {
    intents: Intents.GUILD_MESSAGES,
  },
});

const pings$ = client.fromDispatch("MESSAGE_CREATE").pipe(
  RxO.filter((msg) => msg.content === "!ping"),
  RxO.flatMap((msg) =>
    client.createMessage(msg.channel_id, {
      message_reference: { message_id: msg.id },
      content: "Pong!",
    }),
  ),
);

// Subscribe to our side effects
Rx.merge(client.effects$, pings$).subscribe();

Gateway proxy

Larger bots may want to seperate the websocket handling from the bot logic, for zero downtime deployments.

To do this you would pipe the gateway dispatch events into a event streaming tool, like Apache Kafka or Rabbitmq, then subscribe to the events in your bot logic.

See example/gateway-proxy.ts for an example.

Also see the Redis example.

REST proxy

Larger bots may want to funnel all Discord HTTP requests through a single proxy server, to simplify rate limiting.

See example/proxy.ts for an example.

Caching

Droff will only activate the caches that you use. So by default nothing is cached.

To use a cache, you call one of the cache factory methods, optionally passing in a store implementation.

import * as Rx from "rxjs";
import { createClient, Intents } from "../src/mod";

const client = createClient({
  token: process.env.DISCORD_BOT_TOKEN!,
  gateway: {
    // You will need to enable some intents for the corresponding cache.
    intents: Intents.GUILD_EMOJIS | Intents.GUILD_MEMBERS,
  },
});

const [roleCache, roleCacheEffects$] = client.rolesCache();

// Subscribe to the cache effects if you want to populate the cache from the
// gateway events
Rx.merge(client.effects$, roleCacheEffects$).subscribe();

// You can then use the cache:
roleCache.getForParent("guild id xxx").then((map) => map.get("role id xxx"));

What's missing

Just a heads up that is a relatively new client library. You should note that:

  • There isn't much documentation
  • There isn't anything implemented for Voice channels
  • Some caches will be missing
  • No benchmarking / optimization has been done at this point

Pull requests are more than welcome :)

0.43.6

12 months ago

0.43.5

1 year ago

0.43.4

1 year ago

0.43.0

2 years ago

0.40.0

2 years ago

0.37.0

2 years ago

0.41.0

2 years ago

0.38.1

2 years ago

0.38.0

2 years ago

0.42.0

2 years ago

0.39.1

2 years ago

0.39.0

2 years ago

0.43.3

1 year ago

0.43.1

2 years ago

0.43.2

1 year ago

0.36.0

2 years ago

0.36.0-alpha.0

2 years ago

0.36.0-alpha.1

2 years ago

0.35.0

2 years ago

0.34.2

2 years ago

0.34.1

2 years ago

0.34.0

2 years ago

0.33.0

2 years ago

0.32.2

2 years ago

0.32.1

2 years ago

0.20.1

2 years ago

0.32.0

2 years ago

0.29.0

2 years ago

0.25.0

2 years ago

0.21.2

2 years ago

0.21.1

2 years ago

0.29.1

2 years ago

0.21.0

2 years ago

0.26.0

2 years ago

0.22.1

2 years ago

0.22.0

2 years ago

0.19.0

2 years ago

0.19.1

2 years ago

0.19.2

2 years ago

0.20.0-alpha.0

2 years ago

0.30.2

2 years ago

0.30.1

2 years ago

0.30.0

2 years ago

0.27.2

2 years ago

0.27.1

2 years ago

0.27.0

2 years ago

0.23.1

2 years ago

0.23.0

2 years ago

0.27.6

2 years ago

0.27.5

2 years ago

0.27.4

2 years ago

0.27.3

2 years ago

0.20.1-alpha.4

2 years ago

0.20.1-alpha.3

2 years ago

0.20.1-alpha.2

2 years ago

0.20.1-alpha.1

2 years ago

0.20.1-alpha.0

2 years ago

0.31.0

2 years ago

0.28.0

2 years ago

0.21.0-alpha.4

2 years ago

0.21.0-alpha.3

2 years ago

0.21.0-alpha.2

2 years ago

0.24.1

2 years ago

0.21.0-alpha.1

2 years ago

0.24.0

2 years ago

0.21.0-alpha.0

2 years ago

0.18.1

2 years ago

0.18.2

2 years ago

0.18.3

2 years ago

0.18.0

2 years ago

0.17.19

3 years ago

0.17.18

3 years ago

0.17.17

3 years ago

0.17.16

3 years ago

0.17.14

3 years ago

0.17.12

3 years ago

0.17.10

3 years ago

0.17.11

3 years ago

0.17.9

3 years ago

0.17.8

3 years ago

0.17.7

3 years ago

0.17.6

3 years ago

0.17.4

3 years ago

0.17.5

3 years ago

0.17.2

3 years ago

0.17.3

3 years ago

0.17.0

3 years ago

0.17.1

3 years ago

0.15.4

3 years ago

0.15.5

3 years ago

0.15.3

3 years ago

0.16.3

3 years ago

0.16.4

3 years ago

0.16.0

3 years ago

0.16.1

3 years ago

0.16.2

3 years ago

0.13.6

3 years ago

0.13.7

3 years ago

0.13.8

3 years ago

0.13.9

3 years ago

0.11.0

3 years ago

0.11.1

3 years ago

0.13.0

3 years ago

0.11.2

3 years ago

0.13.1

3 years ago

0.11.3

3 years ago

0.15.0

3 years ago

0.13.2

3 years ago

0.15.1

3 years ago

0.13.3

3 years ago

0.15.2

3 years ago

0.13.4

3 years ago

0.13.5

3 years ago

0.13.12

3 years ago

0.13.11

3 years ago

0.13.10

3 years ago

0.14.5

3 years ago

0.14.6

3 years ago

0.14.7

3 years ago

0.10.1

3 years ago

0.12.0

3 years ago

0.10.2

3 years ago

0.12.1

3 years ago

0.14.0

3 years ago

0.12.2

3 years ago

0.14.1

3 years ago

0.12.3

3 years ago

0.14.2

3 years ago

0.12.4

3 years ago

0.14.3

3 years ago

0.12.5

3 years ago

0.14.4

3 years ago

0.12.6

3 years ago

0.10.0

3 years ago

0.9.3

3 years ago

0.9.0

3 years ago

0.9.2

3 years ago

0.9.1

3 years ago

0.8.3

3 years ago

0.8.2

3 years ago

0.8.1

3 years ago

0.8.0

3 years ago

0.7.1

3 years ago

0.7.0

3 years ago

0.6.0

3 years ago

0.5.0

3 years ago

0.4.5

3 years ago

0.4.4

3 years ago

0.4.3

3 years ago

0.4.2

3 years ago

0.4.1

3 years ago

0.4.0

3 years ago

0.3.4

3 years ago

0.3.3

3 years ago

0.3.2

3 years ago

0.3.1

3 years ago

0.3.0

3 years ago

0.2.6

3 years ago

0.2.5

3 years ago

0.2.4

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago