Skip to content

fuwa-org/fuwa

Repository files navigation

fuwa

fuwa is a small, lightweight library for use in Node.js for interaction with the popular text and VoIP instant messaging application Discord through its public bot API.

Installation

While fuwa is under heavy alpha development, some components of it are publicly released. See installation.md for installation details.

Getting started

fuwa is designed for use by developers familiar with the Discord API, and does not provide heavy abstractions like other libraries. If this isn't for you, see the related projects.

A simple ping/pong bot using @fuwa/ws, @fuwa/model, @fuwa/rest and discord-api-types would resemble the following:

import { GatewayManager } from '@fuwa/ws';
import { Message } from '@fuwa/model';
import RESTManager from '@fuwa/rest';
import { APIMessage } from 'discord-api-types';

const gateway = new GatewayManager('my bot token');
const rest = new RESTManager('Bot <my token>');

gateway.on('MESSAGE_CREATE', async (message: APIMessage) => {
  // convert to a typed camelCase object
  const msg = new Message(message);

  if (msg.content.startsWith('!ping')) {
    await rest.createMessage(msg.channelID, {
      content: 'pong!',
      message_reference: {
        message_id: msg.id,
      },
    });
  }
});

Links