# Addons Structure

## File Structure

All addon files for SupportBot are located in the following directories:

* <mark style="color:green;">**`/Addons/`**</mark>: This is the main folder where you can start building your addon.
* <mark style="color:green;">**`/Addons/Configs/`**</mark>: This is where you can store your addon's configuration files.
* <mark style="color:green;">**`/Addons/Data/`**</mark>: This is where you can store any data files, such as `.json`.

The addon structure is located in <mark style="color:green;">**`/Structures/Addon.js`**</mark>

```
/Addons/
    ├── Configs/
    │   └── exampleaddon.yml
    ├── Data/
    │   └── exampleaddon.json
    └── Commands/
        └── exampleaddon.js
```

## Creating a Command

To start creating a command you would firstly need to create a new `.js` file inside the `/Addons/` directory.&#x20;

1. Inside the `.js` file, start by defining the initializing the environment and importing the modules.

```javascript
const Discord = require("discord.js");
const { Command } = require('../Structures/Addon.js');
const fs = require("fs");
const yaml = require("js-yaml");

const { Command } = require('../Structures/Addon.js');
```

2. Now, you'll need to load in the configuration files

```javascript
// Loads the bots main configuration file.
const supportbot = yaml.load(fs.readFileSync("./Configs/supportbot.yml", "utf8"));

// Loads your Addons configuration file.
const supportbot = yaml.load(fs.readFileSync("./Configs/supportbot.yml", "utf8"));
```

#### Defining a Command

3. Use `module.exports` to export a new instance of the `Command` class. This object includes properties like `name`, `description`, `options`, and `permissions`. It also includes an `async run` method that contains the logic for what happens when the command is executed.

```javascript
module.exports = new Command({
    name: "command_name",
    description: "A brief description of the command",
    options: [],
    permissions: ["PermissionType"],

    async run(interaction) {
        // The command logic goes here
    },
});
```

4. Inside the `run` method, you define what the command does. This might involve replying to the interaction, manipulating messages, or anything else the bot should do when the command is triggered.

```javascript
async run(interaction) {
    const exampleEmbed = new Discord.EmbedBuilder()
        .setDescription(`This is a response from the command.`)
        .setColor(supportbot.Embed.Colours.General);

    interaction.reply({
        embeds: [exampleEmbed],
    });
}
```

### Example Command

Here’s a full example of a simple command that responds with the bot's ping:

```javascript
const Discord = require("discord.js");
const { Command } = require('../Structures/Addon.js');
const fs = require("fs");
const yaml = require("js-yaml");

const { Command } = require('../Structures/Addon.js');

// Loads the bots main configuration file.
const supportbot = yaml.load(fs.readFileSync("./Configs/supportbot.yml", "utf8"));

// Loads your Addons configuration file.
const supportbot = yaml.load(fs.readFileSync("./Configs/supportbot.yml", "utf8"));

module.exports = new Command({
    name: "ping",
    description: "Responds with the bot's latency",
    options: [],
    permissions: ["SendMessages"],

    async run(interaction) {
        const PingEmbed = new Discord.EmbedBuilder()
            .setDescription(`Pong! \`${interaction.client.ws.ping} ms\``)
            .setColor(supportbot.Embed.Colours.General);

        interaction.reply({
            embeds: [PingEmbed],
        });
    },
});
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://emerald-services.gitbook.io/emeraldsrv/bots/supportbot/addons.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
