* 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>
2.8 KiB
sidebar_position
| sidebar_position |
|---|
| 2 |
Create Structure
Structures are often used to transform data and add methods to existing objects. To make it easier to work with them.
Imagine you have a channel object to which you want to send a message.
const data = {
id: 806947972004839444n,
name: "spam-and-bots",
};
The recommended way would be:
await client.helpers.sendMessage(data.id, { content: "hello" });
However, you probably want to use something shorter, such as the following:
const Channel {
constructor(client, data) {
this.client = client;
this.id = data.id;
this.name = data.name;
}
async send(options) {
return await client.helpers.sendMessage(this.id, options);
}
}
Now you can use the .send() method on the channel object without using such a long code:
const channel = new Channel(client, data);
await channel.send({ content: "hello" });
Moreover, you can modify the .send() method to better suit your use case e.g not send the message if the channel is
blacklisted.
This naturally opens a lot of opportunities and makes coding a lot easier. Because you decide what you want to do with the data, how the methods are named and how you want to process the request.
Using Template Structures:
When you are migrating from another library, you'll likely choose to continue using special structures. Therefore why we have ready-made structures in our template repo:
We recommend that you clone the whole template repo, since some structures are based on other files.
Using the Structures:
const Guild = require("./structures/Guild"); // Path to your structure
const guild = new Guild(client, data); // DiscordenoClient and DiscordenoPayloadData
Some popular methods have been added to the structures so that you can use them without having to come up with your own. Of course, you can add your own methods and customize the structures to fit your needs.
Next we're going to give a better insight into how create Embeds and Components with the
template structures.