UNPKG

@confis/discordapiwrapper

Version:

A fast and lightweight discord api wrapper.

54 lines (51 loc) 1.29 kB
/** * Base class for all API objects. */ class Base { constructor(client) { Object.defineProperty(this, "_client", { value: client, configurable: false, enumerable: false, }); } /** * Returns the client */ get client() { return this._client; } _clone() { return Object.assign(Object.create(this), this); } /** * Returns a JSON representation of the object. */ toJson() { const dict = {}; for (const [k, v] of Object.entries(this)) { if (k !== "client") Reflect.set(dict, k, v?.id ?? v?.toJSON?.() ?? v); } return dict; } _patch(data) { } } /** * Represents a webhook client. */ class WebhookClient extends Base { constructor(options, client) { super(client); Object.assign(this, options); } /** * Sends a message to the webhook. * @param content The content of the message. Can be a string or a WebhookContentOptions object. * @returns A Promise that resolves with the sent message. */ async send(content) { return await this.client.rest.sendWebhookMessage(content, this.id, this.token); } } exports.WebhookClient = WebhookClient;