Bot status

require('module-alias/register');
const mongo = require('./mongo');
const { Client, Collection } = require('discord.js');
const client = new Client({ partials: ['MESSAGE', 'REACTION'] });

client.config = require('./config');
client.commands = new Collection();

const { registerEvents, registerCommands } = require('./utils/registry');

client.once('ready', async () => {
console.log(`Connected to Discord as ${client.user.tag}`);
await mongo().then(async () => console.log('Connected to Mongo'));
await registerEvents(client, '../events');
await registerCommands(client, '../commands');

updateBotStatus(); // Initial status update

// Update status when the bot joins or leaves a guild
client.on('guildCreate', updateBotStatus);
client.on('guildDelete', updateBotStatus);
});

client.login(client.config.token);

function updateBotStatus() {
const serverCount = client.guilds.cache.size;
const statusMessage = `Serving ${serverCount} servers`;
console.log(`Updating status to: ${statusMessage}`);
client.user.setPresence({
activities: [{ name: statusMessage, type: 'WATCHING' }],
status: 'online'
}).then(() => {
console.log('Status set successfully');
}).catch(console.error);
}
require('module-alias/register');
const mongo = require('./mongo');
const { Client, Collection } = require('discord.js');
const client = new Client({ partials: ['MESSAGE', 'REACTION'] });

client.config = require('./config');
client.commands = new Collection();

const { registerEvents, registerCommands } = require('./utils/registry');

client.once('ready', async () => {
console.log(`Connected to Discord as ${client.user.tag}`);
await mongo().then(async () => console.log('Connected to Mongo'));
await registerEvents(client, '../events');
await registerCommands(client, '../commands');

updateBotStatus(); // Initial status update

// Update status when the bot joins or leaves a guild
client.on('guildCreate', updateBotStatus);
client.on('guildDelete', updateBotStatus);
});

client.login(client.config.token);

function updateBotStatus() {
const serverCount = client.guilds.cache.size;
const statusMessage = `Serving ${serverCount} servers`;
console.log(`Updating status to: ${statusMessage}`);
client.user.setPresence({
activities: [{ name: statusMessage, type: 'WATCHING' }],
status: 'online'
}).then(() => {
console.log('Status set successfully');
}).catch(console.error);
}
5 Replies
d.js toolkit
d.js toolkit•4mo 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!
Flamingavin
FlamingavinOP•4mo ago
No description
Amgelo
Amgelo•4mo ago
that's v14 syntax, you're on v12 which is really old btw, you should update
Amgelo
Amgelo•4mo ago
Discord.js Guide
A guide made by the community of discord.js for its users.
Flamingavin
FlamingavinOP•4mo ago
lmfao I coded this bot years ago and it still works amazing 🤣
Want results from more Discord servers?
Add your server