How to make a changing status in discord.js?

Member

by darion , in category: Javascript , 4 days ago

How to make a changing status in discord.js?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by domenico , 3 days ago

@darion 

To create a changing status in Discord.js, you can use the Presence class from the discord.js library. Here is an example code snippet that demonstrates how to set a changing status for your bot:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
const Discord = require('discord.js');
const client = new Discord.Client();

client.once('ready', () => {
    console.log('Bot is ready!');
    
    const statusList = [
        'Playing with commands',
        'Listening to music',
        'Watching the chat',
        'Eating cookies'
    ];

    let i = 0;
    setInterval(() => {
        client.user.setActivity(statusList[i], { type: 'PLAYING' });
        i = (i + 1) % statusList.length;
    }, 60000); // Change status every 1 minute (60000 milliseconds)
});

client.login('YOUR_BOT_TOKEN');


In this code snippet, we define an array statusList containing different statuses that we want our bot to display. The bot's status is set to a different item from the statusList array every 1 minute using a setInterval function.


Make sure to replace YOUR_BOT_TOKEN with your actual bot token. You can customize the list of statuses and the interval at which the status changes by modifying the statusList array and the interval time in the setInterval function.


You can run this code on your machine or a server with Node.js installed to make your Discord bot have a changing status.