Skip to main content

How To Update Your NodeJS Discord Bot’s Status

1. Log In to Your Panel


2. Select the ‘Files’ Tab

Cybrancee Panel in the files page, "Files" tab on the sidebar is highlighted

3. Create the Configurations File

Create a new file called config.json then paste the following code.

Pterodactyl Panel, Create File dialog. Enter File Name (config.json)

This file stores the bot token and the desired status settings. Using a separate JSON file keeps the main script clean and prevents accidental sharing of the bot token.

{
  "token": "YOUR_BOT_TOKEN_HERE",
  "statusText": "!help | !ping",
  "statusType": "idle"
}

4. Create Your Main Bot’s File

Create a new file called index.js then paste the following code.

Cybrancee Panel, Create File dialog. Enter File Name (index.js)

What this code does:

  • Imports Necessary Tools: It pulls the Client and ActivityType from the discord.js library to allow communication with the Discord API.
  • Loads Private Settings: It reads the config.json file to securely access the bot token and status preferences without hardcoding them.
  • Creates a Connection Point: It sets up a new Client instance with Guilds intents, which is the basic permission required to stay connected to servers.
  • Wait for Connection: It uses a ready event listener to ensure the bot is fully logged in before attempting to update any profile information.
  • Updates Visual Identity: It executes setPresence to change the bot’s activity to “Playing” and sets the text to the value defined in the configuration.
  • Sets Online Status: It determines the color of the status icon (e.g., green for online) based on the statusType provided.
  • Authenticates: It completes the process by using client.login to sign the bot into Discord using the unique token.
const { Client, GatewayIntentBits, ActivityType } = require('discord.js');
const config = require('./config.json');

// Initialize the Discord Client
const client = new Client({ intents: [GatewayIntentBits.Guilds] });

// Runs once when the bot becomes ready
client.once('ready', () => {
    console.log(`Logged in as ${client.user.tag}`);

    // Applies the presence settings
    client.user.setPresence({
        activities: [{ 
            name: config.statusText, 
            type: ActivityType.Playing 
        }],
        status: config.statusType,
    });
});

// Logs the bot into Discord
client.login(config.token);

Example Of The Presence:

Discord Bot - Showing Presence

Discord Bot Hosting

Starts at $1.49

External link icon

Was this article helpful?
Please Share Your Feedback
How Can We Improve This Article?
Table of Contents