- What's your exact discord.js
npm list discord.jsand nodenode -vversion? - Not a discord.js issue? Check out #1081585952654360687.
- 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
#Ehm?
37 messages · Page 1 of 1 (latest)
That’s usually happening if you have a setInterval trying to setPresence on a not-logged in client
client.user.setActivity(`over ${client.guilds.cache.size} servers | /help`, { type: ActivityType.Watching });
setInterval(() => client.user.setActivity(`over ${client.guilds.cache.size} servers | /help`, { type: ActivityType.Watching }), 30000);```
I mean it never was not logged in since it appeared on the bot that was live
I mean, i only catch errors within try catch, i dont really listen to em
Bots need to reconnect from time to time. So there’s always time where they aren’t logged in
but can it crash the bot? If so, whats a work around for it ?
Don’t do that on an interval and instead do it in guildCreate/guildDelete event when that number actually changes (and on shardReady initially and after each reconnect )
yeah not in the sharding phase yet XD
so just client.user.setActivity in every guildAdd call?
Also do you recon its smart to save the number in a DB so its easier to display it on a website? Or am I just supposed to call to discords API, totally offtopic here iknow, just popped in my head
You have one shard. So that event is exactly what you want, because it emits on every (re)connect, not just the initial one
so just shardReady just like the ready file?
Either call to your bot’s own API if you make one. Or discord‘s but then you need your token in that website server too
what would ya recommend for this usage? Like eventually id like a web panel too so id need the token anyway
Why? I‘d recommend having an API on your bot and query that from your website‘s server. Or run the server from the bot‘s process if that’s feasible
I mean... the bot is on the same VPS anyway so that wouldnt hurt.. how about getting guild channels tho? or is that someht i can dowithout bot tokens
Same answer
Well, if that's the case it's much safer, thanks!
Hi,
shardReady.js
module.exports = {
name: 'shardReady',
async execute(client) {
await client.user.setActivity(`over ${client.guilds.cache.size} servers | /help`, { type: ActivityType.Watching });
}
}```
shardResume.js
```js
module.exports = {
name: 'shardResume',
async execute(client) {
await client.user.setActivity(`over ${client.guilds.cache.size} servers | /help`, { type: ActivityType.Watching });
}
}
like this i'd assume correct?
yeah this is not working
node:events:492
throw er; // Unhandled 'error' event
^
TypeError: Cannot read properties of undefined (reading 'setActivity')
shardReady emits with an id (number), not the client
That event should be added directly in your file where you define client. Because it doesn’t emit with anything you can get the client from
ahh, i need manager instead of client for this?
No? Where did you get manager from what I said
still returning 0, and this is the index
Well, the first shard has id 0, so that’s expected
But you have the client variable there to call setActivity on
So:
client.on("shardReady", async (id) => {
client.user.setActivity(`over ${client.guilds.cache.size} servers | /help`, { type: ActivityType.Watching });
});``` within index?
and then id sassume shardResume is working just fine?
You don’t need to do that on shardResume at all
ah since its on shardStart already correct?
shardReady but yes
const { ActivityType } = require("discord.js");
module.exports = {
name: 'guildCreate',
async execute(client) {
await client.user.setActivity(`over ${client.guilds.cache.size} servers | /help`, { type: ActivityType.Watching });
}
}
So should this be in the main too