UNPKG

@tycrek/discord-hookr

Version:

A lightweight and easy way to send webhooks to Discord, without the added baggage of a full API client.

89 lines (88 loc) 2.36 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EmbedBuilder = void 0; /** * Converts a hex color to an integer */ const formatColor = (hex) => parseInt(hex.replace('#', ''), 16); /** * Builds an embed to be passed into a Webhook Payload */ class EmbedBuilder { embed; constructor() { this.embed = {}; } setTitle(title) { this.embed.title = title; return this; } setDescription(description) { this.embed.description = description; return this; } setURL(url) { this.embed.url = url; return this; } setUrl(url) { this.setURL(url); return this; } setTimestamp(timestamp = new Date()) { // todo: test if this works as intended if (typeof timestamp === 'string') timestamp = new Date(timestamp); this.embed.timestamp = timestamp.toISOString(); return this; } setColor(color) { this.embed.color = formatColor(color); return this; } setImage(image) { this.embed.image = image; return this; } /** * Please note that as of 2022-12-23, Webhooks DO NOT support the Video field. * @deprecated * @see https://discord.com/developers/docs/resources/webhook#execute-webhook-jsonform-params */ setVideo(video) { this.embed.video = video; return this; } setThumbnail(thumbnail) { this.embed.thumbnail = thumbnail; return this; } setFooter(footer) { this.embed.footer = footer; return this; } /** * Please note that as of 2022-12-23, Webhooks DO NOT support the Provider field. * @deprecated * @see https://discord.com/developers/docs/resources/webhook#execute-webhook-jsonform-params */ setProvider(provider) { this.embed.provider = provider; return this; } setAuthor(author) { this.embed.author = author; return this; } addField(field) { if (!this.embed.fields) this.embed.fields = []; this.embed.fields.push(field); return this; } getEmbed() { return this.embed; } } exports.EmbedBuilder = EmbedBuilder; ;