1.0.3 • Published 2 years ago

eris-threads v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

About the package

Eris-threads is a sharding and cluster manager for discord bots based on eris. Eris-threads spreads shards evenly among your cores. Eris-threads is based on eris-sharder (an updated version). Supports CommonJS and ESM.

You can find examples and usage here.

Requirements

Installation

npm:

npm install eris-threads eris

yarn:

yarn add eris-threads eris

pnpm:

pnpm add eris-threads eris

Example

Directory Tree

In this example the directory tree will look something like this:

Project/
├── node-modules/
│   ├── eris-threads
|
├── main.js
│
├── index.js

Example of index.js

const { ShardingManager } = require('eris-threads');

const shardManager = new ShardingManager('/main.js', {
  token: 'botToken',
  stats: true,
  debug: true,
  guildsPerShard: 1500,
  webhooks: {
    shard: {
      id: 'webhookID',
      token: 'webhookToken',
      embed: {} // Custom embed if you wish
    },
    cluster: {
      id: 'webhookID',
      token: 'webhookToken',
      embed: {}
    },
  },
  clientOptions: {
    messageLimit: 150,
    defaultImageFormat: 'png',
  },
});

shardManager.spawn();

Example of main.js

const { Base } = require('eris-threads');

class Bot extends Base {
  constructor(bot) {
    super(bot);
  }
}

module.exports = Bot;

You can start your bot using

node index.js

Sharding Manager Options

NameTypeDescription
pathToMainFilestringFile path that exports the Base class. The class must containt a method called "launch". In the constructor the only paramater you should put is for the bot.
options.tokenstringA discord bot token
options.statsbooleanEnables stats output if true.
options.webhooksobjectWebhook options to send to a channel. Example: {shard: {id: "webhookID", token: "webhookToken"}, cluster:{id: "webhookID", token: "webhookToken"}}
options.clientOptionsobjectEris client options. You can find them here
options.clustersnumberThe number of clusters you want to spawn. Defaults to the amount of cores on your system
options.clusterTimeoutnumberNumber of seconds between starting up clusters. Values lower than 5 may lead to an Invalid Session on first shard.
options.shardsnumberThe number of shards you want to spwan. Defaults gateway reccommendation, taking into account options.guildsPerShard
options.firstShardIDnumberID of the first shard to start on this instance. Defaults to 0
options.lastShardIDnumberID of the last shard to start on this instance. Defaults to options.shards - 1
options.debugbooleanBoolean to enable debug logging.
options.noConsoleOveridebooleanBoolean to disable or enable console overide. Default is false
options.statsIntervalnumberInterval to release the stats event in milliseconds. Defaults to every minute
options.guildsPerShardnumberThe number of guilds per shard. Defaults to 1300. Overriden if you only have 1 shard.

Base

When you extend the Base class (main.js) you get access to this.bot, this.clusterID, and this.ipc

this.bot is the eris client

this.clusterID will return the cluster id.

IPC Methods

NameExampleDescription
registerthis.ipc.register(event, callback);Using this you can register to listen for events and a callback that will handle them
unregisterthis.ipc.unregister(event);Use this to unregister for an event
broadcastthis.ipc.broadcast(name, message);Using this you can send a custom message to every cluster
sendTothis.ipc.sendTo(cluster, name, message)Using this you can send a message to a specific cluster
fetchUserawait this.ipc.fetchUser(id)Using this you can search for a user by id on all clusters
fetchGuildawait this.ipc.fetchGuild(id)Using this you can search for a guild by id on all clusters
fetchChannelawait this.ipc.fetchChannel(id)Using this you can search for a channel by id on all clusters
1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago