Custom Statuses

How to set custom statuses with your Ready event

We can also add custom statuses to our Discord Bot, so it will say "Playing (Game)" or "Watching Members".

To do this, we need to require ActivityType from Discord.js, so to do this, we need to add it to our code:

const { ActivityType } = require('discord.js')

module.exports = (client) => {
  console.log(`✅ ${client.user.username} is now online.`);
};

Now below our console.log() function, we can call client.user.setActivity({}) and this will take an object.

Say you want your status to be "Watching Members," we need to set that as our name and type, so we will add this in our client.user.setActivity({}) function.

const { ActivityType } = require('discord.js')

module.exports = (client) => {
  console.log(`✅ ${client.user.username} is now online.`);

  client.user.setActivity({
    name: "Members",
    type: ActivityType.Watching,
  });
};

Here, we are setting the name (what appears after the type) to "Members", and setting the type to "Watching."

The available types go as follows:

ActivityType.Playing ActivityType.Watching ActivityType.Listening ActivityType.Competing ActivityType.Streaming ActivityType.Custom

The Streaming Type needs a URL of an active stream, so any streams that are ended/old will not work properly.

The Custom Type needs Name, and optionally, State.

  • Name: The text of the custom status

  • State (Optional): The emoji that appears to the left of the text.

🔗 Changing Statuses

If you would like changing statuses, or let us say multiple statuses, you can do this by using some simple math.

For this example, we will be adding one that shows a website link and one that shows the member/user count of a guild.

First, we need to define our guild so we can find the member count of that guild, so we can take our previous code and change it to this:

const { ActivityType } = require('discord.js')

module.exports = (client) => {
  const guild = client.guilds.cache.get("Your Guild ID")

  console.log(`✅ ${client.user.username} is now online.`);

  client.user.setActivity({
    name: "Members",
    type: ActivityType.Watching,
  });
};

The next thing we want to do is define our statuses, and we can do this as an array of objects.

let status = [
    {
      name: "Website.com",
      type: ActivityType.Watching,
    },
    {
      name: `${guild.memberCount} users`,
      type: ActivityType.Watching,
    },
  ];

This will store our statuses in status. These will both be using the Watching type.

Now that we have defined our statuses, we need to add them to the code. We also need to remove the old function to set our status because it will be changed later on.

const { ActivityType } = require('discord.js')

module.exports = (client) => {
  const guild = client.guilds.cache.get("Your Guild ID")

  let status = [
    {
      name: "Website.com",
      type: ActivityType.Watching,
    },
    {
      name: `${guild.memberCount} users`,
      type: ActivityType.Watching,
    },
  ];
  
};

Now it's time to add the math and functions to set our activity. We will start by adding a try-catch block just in case our code. This will prevent it from crashing.

const { ActivityType } = require('discord.js')

module.exports = (client) => {
  const guild = client.guilds.cache.get("Your Guild ID")

  let status = [
    {
      name: "Website.com",
      type: ActivityType.Watching,
    },
    {
      name: `${guild.memberCount} users`,
      type: ActivityType.Watching,
    },
  ];
  
  try {
  
  } catch (error) {
  
  }
  
};

And inside the try block, we can write our math code, which we will save in a variable called random.

const { ActivityType } = require('discord.js')

module.exports = (client) => {
  const guild = client.guilds.cache.get("Your Guild ID")

  let status = [
    {
      name: "Website.com",
      type: ActivityType.Watching,
    },
    {
      name: `${guild.memberCount} users`,
      type: ActivityType.Watching,
    },
  ];
  
  try {
    setInterval(() => {
      let random = Math.floor(Math.random() * status.length);
      client.user.setActivity(status[random]);
    }, 10000)
    
    console.log(`✅ ${client.user.username} is now online.`);
  } catch (error) {

}
  
};

This will randomize the statuses and apply a new one every 10 seconds, and will also tell us when our bot is online.

Now we can console log our error if there is one:

try {
    setInterval(() => {
      let random = Math.floor(Math.random() * status.length);
      client.user.setActivity(status[random]);
    }, 10000)
    
    console.log(`✅ ${client.user.username} is now online.`);
  } catch (error) {
      console.log(`⚠️ Error Applying Status: ${error}`);
}

This will finish off our code for statuses, and if you want to add more custom ones, just add them to your statuses array, following the same format as the ones from before.

Last updated