1.0.3 • Published 4 years ago

discord-hook-api v1.0.3

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

Discord Hook

A Node.js Module to post to Discord Webhooks.

Examples

Check the example.js in the examples folder

Installation

Simply run npm i discord-hook-api or yarn add discord-hook-api

Documentation

Put this somewhere on the top of your document

const { Hook, Embed } = require('discord-hook-api')

Hook Methods

To get started, you need to give up the webhook URL and append the methods using .method(argument) on the next lines.

webhook(url)

Pass the url for the webhook, there are two ways to pass it. Argument(s): string

new Hook()
  .webhook(webhook_url_here)
// or
new Hook(webhook_url_here)

addEmbed(embed)

Simply add an embed to the post by using the addElement method, you pass an embed which you can make as well. More information later in this documenation. Argument(s): embed

new Hook()
  .addEmbed(embed)

setAvatar(avatar)

Overwrite the avatar set in the webhook settings on Discord, you need to pass an URL to it which directly leads to a file. You can use something like file.coffee for it. Argument(s): string

new Hook()
  .setAvatar(url)

setContent(content)

This is the message you want to display, you can leave it blank if you are gonna send an embed. Argument(s): string

new Hook()
  .setAvatar(content)

setUsername(username)

Overwrite the username set in the webhook settings on Discord, you need to pass a string. Argument(s): string

new Hook()
  .setUsername(username)

setTts()

Want to make the webhook speak to all it's users, you can do it. Argument(s): none

new Hook()
  .setTts(boolean)

send()

Done making the message? Run this method and it will be delivered to Discord. Argument(s): none

new Hook()
  .send()

Embed Methods

Want to send a fancy message? The Embed class got you covered. Start with the following and append the methods using .method(argument) on the next lines.

const embed = new Embed()

setTitle(title)

Set the title of the embed Argument(s): string

const embed = new Embed()
  .setTitle(title)

setDescription(description)

Set the description of the embed Argument(s): string

const embed = new Embed()
  .setDescription(description)

setUrl(url)

Set the url of the embed Argument(s): string

const embed = new Embed()
  .setUrl(url)

setTimestamp(timestamp)

Set the timestamp for the footer of the timestamp, you don't need to pass an argument and it will pick the current time. Argument(s): string

const embed = new Embed()
  .setTimestamp(timestamp)

setColor(setColor)

Set the color of the embed Argument(s): integer

const embed = new Embed()
  .setColor(setColor)

setFooter(text, icon)

Set the footer of the embed, the icon is optional if you are using this method. Argument(s): string, string

const embed = new Embed()
  .setFooter(text, icon)

setImage(url)

Set the image of the embed Argument(s): string

const embed = new Embed()
  .setImage(url)

setThumbnail(url)

Set the thumbnail of the embed Argument(s): string

const embed = new Embed()
  .setThumbnail(url)

setVideo(url)

Set the video of the embed Argument(s): string

const embed = new Embed()
  .setVideo(url)

setAuthor(name, icon, url)

Set the author of the embed, icon and url are optional. Argument(s): string, string, string

const embed = new Embed()
  .setAuthor(name, icon, url)

addField(name, value, inline)

Add a field to the embed, max is 25 fields. Argument(s): string

const embed = new Embed()
  .addField(name, value, inline)

License

Released under the MIT License