hookcord
Version:
A user-friendly, sleek and fast client used to create and send Discord Webhooks.
116 lines (110 loc) • 4.45 kB
Markdown
[](https://discord.gg/PyEecVA)
[](https://david-dm.org/maxrumsey/hookcord)
[](https://coveralls.io/github/maxrumsey/hookcord?branch=master)
[](https://travis-ci.org/maxrumsey/hookcord)
[](https://npmjs.org/package/hookcord)
[](https://npmjs.org/package/hookcord)
[](https://github.com/maxrumsey/hookcord)
[](https://greenkeeper.io/)
[](https://packagephobia.now.sh/result?p=hookcord@1.2.1)
<br><br>
[](https://nodei.co/npm/hookcord/)
<br><br>
# 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/](https://maxrumsey.xyz/hookcord)
# Usage
## Installation
```
$ npm i hookcord
```
## Initialisation
```javascript
var hookcord = require('hookcord');
var Hook = new hookcord.Hook()
.login('ID', 'SECRET')
.setPayload(payload)
.fire()
.then(function(response) {})
.catch(function(e) {})
```
Or:
```javascript
var hookcord = require('hookcord');
var Hook = new hookcord.Hook()
.setLink('https://abc.com/webhook')
.setPayload(payload)
.fire()
.then(function(response) {})
.catch(function(e) {})
```
## Messages
```javascript
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](https://maxrumsey.xyz/hookcord/?api).
## Embeds
```javascript
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](https://discordapp.com/developers/docs/resources/channel#embed-object).
More information is available at the [Hookcord documentation](https://maxrumsey.xyz/hookcord/?api).
## Ratelimits
By default, Hookcord will throw an error if it encounters a ratelimit. You can override this by setting a handler function like this:
```javascript
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](https://maxrumsey.xyz/hookcord/?api).
## Parsing Discord.JS Embeds
Hookcord has the ability to parse embeds created via [Discord.JS's RichEmbed](https://discord.js.org/#/docs/main/stable/class/RichEmbed). These parsed embeds can be sent via Hookcord as a Webhook.
```javascript
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](https://github.com/maxrumsey/hookcord)! Also, make sure to join our [Discord Server](https://discord.gg/PyEecVA)!