Wondering what’s next for npm?Check out our public roadmap! »

hookcord

2.0.2 • Public • Published

Discord Dependencies Coverage Status Build Status npm npm npm Greenkeeper badge install size

npm

Hookcord

A user-friendly, sleek and fast client used to create and send Discord Webhooks.

Features

  • Object-oriented
  • Complete coverage of the Discord Webhook API
  • Lightweight but powerful

API Documentation available at maxrumsey.xyz/hookcord/

Usage

Installation

$ npm i hookcord

Initialisation

var hookcord = require('hookcord');
var Hook = new hookcord.Hook()
  .login('ID', 'SECRET')
  .setPayload(payload)
  .fire()
  .then(function(response) {})
  .catch(function(e) {})

Or:

var hookcord = require('hookcord');
var Hook = new hookcord.Hook()
  .setLink('https://abc.com/webhook')
  .setPayload(payload)
  .fire()
  .then(function(response) {})
  .catch(function(e) {})

Messages

var hookcord = require('hookcord');
var Hook = new hookcord.Hook()
  .login('ID', 'SECRET')
  .setPayload({
    'content': 'This displays like a normal message.'
  })
  .fire()
  .then(function(response) {})
  .catch(function(e) {})

More information is available at the documentation.

Embeds

var hookcord = require('hookcord');
var Hook = new hookcord.Hook()
  .login('ID', 'SECRET')
  .setPayload({'embeds': [{ // .setPayload(hookcord.DiscordJS(embed))
    'title': 'Hookcord',
    'description': '',
    'fields': [{
      'name': 'Version',
      'value': '1.0.0',
      'inline': true
    }],
    'timestamp': new Date();
  }]})
  .fire()
  .then(function(response) {})
  .catch(function(e) {})

Embed documentation is available at Discord's Documentation. More information is available at the Hookcord documentation.

Ratelimits

By default, Hookcord will throw an error if it encounters a ratelimit. You can override this by setting a handler function like this:

var hookcord = require('hookcord');
var Hook = new hookcord.Hook()
  .login('ID', 'SECRET')
  .setOptions({
    handler: function(err) {
      console.log('Ratelimit Request Limit: ' + err.limit);
      console.log('Remaining Requests: ' + err.remaining);
      console.log('Time until Reset: ' + err.reset)
    }
  })
  .setPayload({ contents: ':)' })
  .fire()

It provides the remaining requests allowed (0), the total requests permitted (usually 5) and the time until the Ratelimit resets.

More information is available at the Hookcord documentation.

Parsing Discord.JS Embeds

Hookcord has the ability to parse embeds created via Discord.JS's RichEmbed. These parsed embeds can be sent via Hookcord as a Webhook.

var hookcord = require('hookcord');
var Hook = new hookcord.Hook()
  .login('ID', 'SECRET')
  .setPayload(hookcord.DiscordJS(embed))
  .fire()
  .then(function(response) {})
  .catch(function(e) {})

If you attempt to parse a file, the file will be removed and the incident will be logged to console.

Contributing

If you wish to contribute, feel free to open a pull request on the GitHub Repository! Also, make sure to join our Discord Server!

Install

npm i hookcord

DownloadsWeekly Downloads

226

Version

2.0.2

License

MIT

Unpacked Size

33.4 kB

Total Files

18

Last publish

Collaborators

  • avatar