Files
discordeno/template/nodejs/Structures/Embed.js
meister03 b7b2120a6f docs(site, template): add Nodejs Bot Guide (#1998)
* Inital Docs

* Finish Design

* Finish Design

* Add FILE Structure'

* Add Not Ready Template

* Update Template

* Add Command Manager and first Command ping

* Add Command Manager and first Command ping

* Add Embeds Guide & EventManager

* INITIAL FINISH: GUIDE

* FIX TYPOS, LTS's Review, sidebar_position

* Update site/docs/nodejs/getting-started.md

Co-authored-by: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com>

* Fixed Position? Add some comments on template, add changes in review

* Add Interaction Handling, Modals

* format files

* Update site/docs/nodejs/getting-started.md

1

Co-authored-by: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com>

* Update site/docs/nodejs/CommandHandler/command-manager.md

Co-authored-by: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com>

* Fix Review things

* itoh's suggestions

The guide looks very very veery good overall I like it. This commit adds my personal style of writing.
Please review it 🙏.

PS: I hope these are not too many changes .-.

* deno fmt

Co-authored-by: meister03 <root@_HOSTNAME_>
Co-authored-by: ITOH <to@itoh.at>
Co-authored-by: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com>
2022-02-15 13:54:05 +00:00

100 lines
2.1 KiB
JavaScript

class Embed {
constructor(options = {}) {
this.title = options.title;
this.description = options.description;
this.fields = options.fields;
this.thumbnail = options.thumbnail;
this.image = options.image;
this.author = options.author;
this.color = options.color;
this.timestamp = options.timestamp;
this.footer = options.footer;
this.url = options.url;
this.fields = options.fields ?? [];
}
setTitle(title) {
this.title = title;
return this;
}
setDescription(description) {
this.description = description;
return this;
}
setThumbnail(thumbnail) {
this.thumbnail = thumbnail;
return this;
}
setImage(image) {
this.image = image;
return this;
}
setAuthor(author) {
if (typeof author !== "object") throw new Error("Author must be an object");
this.author = author;
return this;
}
setColor(color) {
this.color = color;
return this;
}
setTimestamp(timestamp) {
this.timestamp = timestamp ?? Date.now();
return this;
}
setFooter(footer) {
if (typeof footer !== "object") throw new Error("Footer must be an object");
this.footer = footer;
return this;
}
setURL(url) {
this.url = url;
return this;
}
addField(field) {
this.fields.push(field);
return this;
}
addFields(...fields) {
fields.map((x) => this.addField(x));
return this;
}
toJSON() {
return {
title: this.title,
type: "rich",
description: this.description,
color: this.color,
timestamp: this.timestamp ? new Date(this.timestamp).toISOString() : null,
thumbnail: this.thumbnail,
image: this.image,
fields: this.fields,
url: this.url,
author: this.author
? {
name: this.author.name,
url: this.author.url,
iconUrl: this.author.icon_url || this.author.iconUrl,
}
: null,
footer: this.footer
? {
text: this.footer.text,
iconUrl: this.footer.icon_url || this.footer.iconUrl,
}
: null,
};
}
}
module.exports = Embed;