# Creating your application

## Configuration files <a href="#configuration-files" id="configuration-files"></a>

### config.json

If you're here, you have copied your bot's token. If it's not the case, [click here](/setting-up-an-application.md).

To keep your token safe, you should create a `config.json` file in your bot's folder.

The file should look like this:

{% code title="config.json" %}

```json
{
  "token": "insert token here"
}
```

{% endcode %}

{% code title="Usage:" %}

```javascript
const config = require('./config.json');
console.log(config.token);
```

{% endcode %}

{% hint style="danger" %}
If you're using Git or GitHub Desktop, you should add this file to `.gitignore`&#x20;
{% endhint %}

### Using environment variables <a href="#using-environment-variables" id="using-environment-variables"></a>

There is another way to keep your token safe, and it is a better way. For this you'll need to create a new file named `.env`, your file should look like this:

{% code title=".env" %}

```
TOKEN=TOKEN HERE
```

{% endcode %}

{% code title="Usage:" %}

```javascript
require('dotenv').config();
console.log(process.env.TOKEN);
```

{% endcode %}

#### Installing dotenv

To use .env in your file, you'll need to use dotenv. So let's install it:

{% tabs %}
{% tab title="npm" %}

```bash
npm install dotenv
```

{% endtab %}

{% tab title="yarn" %}

```bash
yarn add dotenv
```

{% endtab %}

{% tab title="pnpm" %}

```bash
pnpm add dotenv
```

{% endtab %}
{% endtabs %}

## Setting up a new bot with TouchGuild

### Creating index.js

To code your bot, you'll need a file called index.js

After creating it, you'll be able to setup your bot.

Here's an example of code:

{% code title="index.js" overflow="wrap" %}

```javascript
// importing TouchGuild
const { Client } = require("touchguild");

// If you created a .env file:
require('dotenv').config();
const client = new Client({ token: process.env.TOKEN });

// If you created a configuration file:
const config = require("./config.json");
const client = new Client({ token: config.token });

client.registerGlobalApplicationCommand({
    name: "ping",
    type: ApplicationCommandType.CHAT_INPUT
});

client.on("interactionCreate", async (interaction)=> {
    if (interaction instanceof CommandInteraction) {
        if (interaction.data.name === "ping") {
            void interaction.createMessage({ content: "Pong!" });
        }
    }
});

client.connect(); // connect to guilded
```

{% endcode %}

You're now ready to create many commands as you want for your bot!

Have fun!


---

# 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://guide.touchguild.com/creating-your-application.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.
