Introduction

To develop and host a Discord bot on Square Cloud, it’s essential to follow a structured sequence of configurations and prerequisites. This technical guide will cover the entire process, from initial setup to production deployment.

Essential Prerequisites

  • Active Discord Account: Fundamental for creating and managing bots on the platform. If you don’t have one, visit the official Discord website to create your account.
  • Square Cloud Account: Hosting platform for your application. Register through the signup page using your email.
  • Active Paid Plan: Ensures dedicated resources and optimized performance for your bot. Check our available plans and choose the most suitable for your needs.

Initial Discord Bot Configuration

Application Creation

Access the Developer Portal and click “New Application”. Define a name for your bot and click “Create” to create the application.

Authentication Token Generation

After creating the application, navigate to the “Bot” tab and click “Reset Token” to generate the authentication token. Copy the generated token for later use in code implementation.

Privileged Intents Activation

With the token configured, activate the necessary intents. Stay in the “Bot” tab, scroll down and locate “Privileged Gateway Intents”. Activate the intents as shown in the image:
Critical Security: Keep your bot token in absolute secrecy. This token grants total control over the bot and should be treated as confidential information.

Bot Development

Node.js Environment Setup
  1. Verify that Node.js is installed on your system. If not, download it from the official Node.js website.
  2. Initialize a new Node.js project:
Terminal
npm init -y
  1. Install the Discord.js library:
Terminal
npm install discord.js
  1. Create a JavaScript file (e.g., index.js) and add the following code to create a basic Discord bot:
index.js
const { Client, GatewayIntentBits } = require("discord.js");

const client = new Client({
  intents: [
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildMessages,
    GatewayIntentBits.MessageContent,
  ],
});

client.on("ready", () => {
  console.log(`${client.user.tag}!`);
});

client.on("messageCreate", (message) => {
  if (message.content === "!hello") {
    message.reply("Hello!");
  }
});

client.login("your token here");

Square Cloud Configuration File

Learn about: how to create the configuration file for Square Cloud.

The squarecloud.app file is a configuration file that will be used to configure your application on Square Cloud. It defines name, description, version, main file, among other essential configurations.

START Field Configuration

Only use this field if you are absolutely sure about what you are doing.
In the Square Cloud configuration file, the START field is optional and only necessary if you are using a custom script to start the bot. In the provided example, the START field is not necessary.

Uploading Your Project to Square Cloud

After following all the steps, package your application files into a zip file where the configuration file is located and upload the bot at Upload. Remember to include the requirements.txt or package.json file, but do not include files like __pycache__ or node_modules. You can get more information about unnecessary files during hosting at automatic-file-deletion-when-deploying-an-application-on-squarecloud.

Testing the Bot

If you followed all the steps correctly, the next step is to invite your bot for testing. To do this, follow these steps:
  1. Access the Developer Portal.
  2. Select your bot.
  3. Navigate to the “OAuth2” tab.
  4. Go to “OAuth2 URL Generator”.
  5. Check the “bot” option.
  6. Choose the permissions your bot will have when invited using this invite.
  7. Below the permissions, an invite link for your bot will be generated. It should look like this:
https://discord.com/oauth2/authorize?client_id=00000000000000&permissions=8&scope=bot
Remember that the client_id in the URL should be replaced with your bot’s actual ID. The permissions value may also need to be adjusted based on the permissions you want your bot to have. Now, to test if everything is working, execute the following command on your server: !hello.

Additional Resources

For more information on creating bots with discord.py and discord.js, visit the official discord.py documentation and the official discord.js guide. There, you’ll find detailed guides, tutorials, and API documentation to help you make the most of these libraries. If you continue facing technical difficulties, our specialized support team is available to assist you. Contact us and we'll be happy to help you resolve any issue.