🎒
TouchGuild Guide
Get back Home
  • TouchGuild's Docs
  • Introduction
  • Privacy Policy
  • 📝Installation & Preparation
  • âš’ī¸Setting up an application
  • 🤖Creating your application
  • Intents
  • Application Commands
    • Registering
    • Command Interactions
    • Components
  • đŸ“ŦManaging messages
    • â„šī¸Tips
    • Original Message concept & how it works
    • Creating embeds
  • Permissions & Roles
  • 😰Reactions
  • Data & Analytics
  • Managing members
    • đŸ’¯Award experience to server members
    • đŸĻĩBan, unban & kick server members
Powered by GitBook
On this page
  • Configuration files
  • config.json
  • Using environment variables
  • Setting up a new bot with TouchGuild
  • Creating index.js

Was this helpful?

Creating your application

PreviousSetting up an applicationNextIntents

Last updated 7 months ago

Was this helpful?

Configuration files

config.json

If you're here, you have copied your bot's token. If it's not the case, .

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

The file should look like this:

config.json
{
  "token": "insert token here"
}
Usage:
const config = require('./config.json');
console.log(config.token);

If you're using Git or GitHub Desktop, you should add this file to .gitignore

Using environment variables

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:

.env
TOKEN=TOKEN HERE
Usage:
require('dotenv').config();
console.log(process.env.TOKEN);

Installing dotenv

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

npm install dotenv
yarn add dotenv
pnpm add dotenv

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:

index.js
// 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

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

Have fun!

🤖
click here