0.1.13 β€’ Published 4 years ago

monbot v0.1.13

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

Monbot

A library with simple API for creating your own discord bots.

:warning: Not recommended for use yet. Under development and api is still shaping up.

Installation

Install using npm install --save monbot discord.js or yarn add monbot discord.js.

Quickstart

Monbot makes it easier to create discord bots with custom commands. Here's quick example:

import { Monbot, createCommand } from 'monbot';

// Create a command that is triggered when word "hello" is found in the message, e.g. "Hello friend!"
const hello = createCommand({
  name: 'hello',
  trigger: /(^|\s+)hello(\s+|$)/i,
  run: ({ channel }) => {
    channel.send('hi πŸ‘‹');
  },
});

// Initialise the bot
Monbot('BOT_AUTH_TOKEN', {
  commands: [hello],
});

You can find expanded example from example/

Bot permissions in discord

For bot to work with adding or removing reactions to messages that are not in its cache, e.g. messages send before bot became online, it requires Read Message History permission.

Without the permission bot cannot fetch non-cached messages and the reactions will not trigger the action.

API documentation

Monbot

TBA

createCommand

Creates a command configuration.

type Command = {
  name: string;
  trigger: RegExp;
  run: (message: Message, { removeTrigger, parseArgs }: CommandExtraParams) => void;
  requiredRoles?: string[];
  adminOnly?: boolean;
  channels?: string[];
  guilds?: string[];
};
FieldDescription
nameName of the command. Displayed in logs
triggerRegular expression that triggers the command
runFunction to run when command is triggered
requiredRolesRole IDs user is required to have to run the command
adminOnlyIs user required to be listed as admin in BotConfig
channelsChannel IDs for channels the command is allowed be run in
guildsGuild IDs for servers the command is allowed be run in

Example

export const hello = createCommand({
  name: 'hello',
  trigger: /(^|\s+)hello(\s+|$)/i,
  run: ({ channel }) => {
    channel.send('hi πŸ‘‹');
  },
});

createReaction

Creates a reaction configuration.

type Reaction = {
  name: string;
  trigger: string | string[];
  onAdd?: (reaction: MessageReaction) => void;
  onRemove?: (reaction: MessageReaction) => void;
  requiredRoles?: string[];
  channels?: string[];
  guilds?: string[];
};
FieldDescription
nameName of the command. Displayed in logs
triggerEmoji name that triggers reaction. Discord's default emoji names are like πŸ˜„or πŸ‘. Custom emojis name's are the same as their alias in server settings, e.g. woah
onAddFunction to run when reaction is added
onRemoveFunction to run when reaction is removed
requiredRolesRole IDs user is required to have to run the command
channelsChannel IDs for channels the command is allowed be run in
guildsGuild IDs for servers the command is allowed be run in

Example

export const wave = createReaction({
  name: 'wave',
  trigger: ['πŸ‘‹'],
  onAdd: ({ message: { channel } }) => {
    channel.send('You added :wave:');
  },
  onRemove: function ({ message: { channel } }) {
    channel.send('You removed :wave:');
  },
});
0.1.13

4 years ago

0.1.12

4 years ago

0.1.11

4 years ago

0.1.10

4 years ago

0.1.8

4 years ago

0.1.9

4 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago