DISCORD STATUT

Hey I want set a statut to my bot discord but he don’t set this is my code :
const { Client, GatewayIntentBits } = require('discord.js');
const axios = require('axios');

const intents = [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
];

const client = new Client({ intents });

const token = 'retired';
const serverStatusURL = 'https://bp.userr00t.com/serverbrowser/api/';
const myServerIP = '154.51.39.124';
const myServerPort = 5006;
const serverListURL = 'https://brokeprotocol.com/servers.json';

client.on('ready', () => {
console.log(`Connecté en tant que ${client.user.tag}`);

updateBotStatus();
});

async function updateBotStatus() {
try {
console.log('Starting bot status update...');

const axiosConfig = {
timeout: 5000,
headers: {
'User-Agent': 'YourBotName/1.0',
},
};

console.log('Sending request to the server...');
const response = await axios.get(serverListURL, axiosConfig);
console.log('Response received successfully.');

const serverList = response.data;

const myServer = serverList.find(server => server.IP === myServerIP && server.Port === myServerPort);

if (myServer) {
const playerCount = myServer.PlayerCount;
const playerLimit = myServer.PlayerLimit;

// Set the bot's status to the player count
client.user.setActivity(`${playerCount} players`, { type: 'PLAYING' });
console.log(`Bot status set to: ${playerCount} players`);
} else {
// If server not found, set status to 'Server offline'
client.user.setActivity('Server offline', { type: 'WATCHING' });
console.log('Bot status set to: Server offline');
}

console.log('Bot status update completed.');
} catch (error) {
console.error('Error updating bot status:', error);
}
}

setInterval(updateBotStatus, 10 * 60 * 1000);

client.login(token);
const { Client, GatewayIntentBits } = require('discord.js');
const axios = require('axios');

const intents = [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
];

const client = new Client({ intents });

const token = 'retired';
const serverStatusURL = 'https://bp.userr00t.com/serverbrowser/api/';
const myServerIP = '154.51.39.124';
const myServerPort = 5006;
const serverListURL = 'https://brokeprotocol.com/servers.json';

client.on('ready', () => {
console.log(`Connecté en tant que ${client.user.tag}`);

updateBotStatus();
});

async function updateBotStatus() {
try {
console.log('Starting bot status update...');

const axiosConfig = {
timeout: 5000,
headers: {
'User-Agent': 'YourBotName/1.0',
},
};

console.log('Sending request to the server...');
const response = await axios.get(serverListURL, axiosConfig);
console.log('Response received successfully.');

const serverList = response.data;

const myServer = serverList.find(server => server.IP === myServerIP && server.Port === myServerPort);

if (myServer) {
const playerCount = myServer.PlayerCount;
const playerLimit = myServer.PlayerLimit;

// Set the bot's status to the player count
client.user.setActivity(`${playerCount} players`, { type: 'PLAYING' });
console.log(`Bot status set to: ${playerCount} players`);
} else {
// If server not found, set status to 'Server offline'
client.user.setActivity('Server offline', { type: 'WATCHING' });
console.log('Bot status set to: Server offline');
}

console.log('Bot status update completed.');
} catch (error) {
console.error('Error updating bot status:', error);
}
}

setInterval(updateBotStatus, 10 * 60 * 1000);

client.login(token);
15 Replies
d.js toolkit
d.js toolkit9mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
Marwan
Marwan9mo ago
I want the status to show the number of players in relation to a game server, which is why the status is lower
treble/luna
treble/luna9mo ago
please read the first bullet point
Marwan
Marwan9mo ago
I use "discord.js": "^14.13.0" And node js 19
d.js docs
d.js docs9mo ago
dtypes v10: ActivityType read more
treble/luna
treble/luna9mo ago
Use that to set the status, not WATCHING
Marwan
Marwan9mo ago
Okay I will test this
d.js docs
d.js docs9mo ago
method ClientUser#setActivity() Sets the activity the client user is playing.
Marwan
Marwan9mo ago
So the problem was the version of node js or discord.js?
treble/luna
treble/luna9mo ago
No, your code
Marwan
Marwan9mo ago
K This is the old or new setup ?
treble/luna
treble/luna9mo ago
the new
Marwan
Marwan9mo ago
I don't quite understand what I need to change This is good no ?
Marwan
Marwan9mo ago
No description
Marwan
Marwan9mo ago
// Set the client user's activity client.user.setActivity('discord.js', { type: ActivityType.Watching }); I have solv the problem Thanks