Giter Site home page Giter Site logo

discord-slim's Introduction

Discord Slim

npm

Lightweight Discord client for Node.js.

Provides access to Discord client gateway and API for Clients. You will probably get banned for this, i dont take responsability. Very minimalistic way without excessive abstractions and dependencies. Also with very low resources usage.

Before you start

Node.js 12+ is required!

Make sure you have some understaning of Discord API.

API

Client - main client class.

Methods

  • Auth(token) - set up token for the client.
  • Connect(intents?) - connect to the gateway to receive intents.
  • Disconnect() - disconnect from the gateway.
  • Request(method, route, data?, auth?) - send a request to Discord API.
  • WsSend(data) - send data to the gateway directly.

? means optional arg.

Events

  • connect - client established a connection to the gateway.
  • disconnect - client disconnected.
  • packet - intent packet received.
  • warn - other noticeable information.
  • error - error appeared, client will continue to work.
  • fatal - fatal error, client will shutdown.

Other exports

Host - contains current Discord domain.
API - contains current Discord API address.
CDN - contains current Discord CDN address.
Routes - base API route constructors.
Permissions - list of known permissions.
Intents - list of known intents.

Installation

npm i discord-slim

Basic bot setup example

const Discord = require('discord-slim');

const client = new Discord.Client();

client.Auth('BOT_TOKEN');
client.Connect(Discord.Intents.GUILDS | Discord.Intents.GUILD_MESSAGES);

// Listen for intent packets
client.on('packet', packet => {
    // packet.t contains intent type
    // packet.d contains intent data
    if(packet.t == 'MESSAGE_CREATE')
        HandleMessage(packet.d);
});

You can read about possible intents here and here.

Scripting and routing

Auth and Connect functions are separated because API requests doesn't actually require connection to the gateway. This is useful if you want only a script that just sends some requests without actual client connection.

const Discord = require('discord-slim');

const client = new Discord.Client();

client.Auth('BOT_TOKEN');
// client.Connect() is not required if you don't need to listen intents

const Routes = Discord.Routes;
// Post a message in some channel
client.Request('POST', Routes.Channel('CHANNEL_ID') + '/messages', { content: 'Hello!' });

Message posting example

Build from source

Install typescript package from npm and run tsc.

discord-slim's People

Contributors

belohnung avatar hanabishirecca avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.