Coding Amendment

Hey guys, I'm getting multiple errors (available if needed) in a specific file, but they all seem to relate to my
var userCount = guild.memberCount;
var userCount = guild.memberCount;
segment. I've tried to fix this myself and research the correct syntax (this is still on djs 12 as I have not had time to upgrade the bot to 14), however I cannot work out what it should be without causing the rest of the bot to crash. Any assistance with either the correct code, or guidance on what to search/where to look would be greatly appreciated. Current code file below:
function updateStats(client) {
const Discord = require('discord.js');
const config = require("../settings/configuration");
const settings = require("../settings/configuration");
const guild = client.guilds.cache.get(settings.BOT_SETTINGS.Guild_ID);
const totalUsers = client.channels.fetch('883654989271154728');
const onlineUsers = client.channels.fetch('883655041813200926');
setInterval(function() {
const interval = (async function() {
for await (const startTime of setInterval(interval, Date.now())) {
const now = Date.now();
console.log(now);
if ((now - startTime) > 1000)
break;
}
console.log(Date.now());
})();
console.log('Getting stats update..')
var userCount = guild.memberCount;
var onlineCount = guild.members.filter(m => m.presence.status === 'online').size
console.log("Total Users: " + userCount);
console.log("Online Users: " + onlineCount);
totalUsers.setName("Total Users: " + userCount)
.then(newChannel => console.log(`Stat channel renamed to: ${newChannel.name}`))
.catch(console.error);
onlineUsers.setName("Online Users: " + onlineCount)
.then(newChannel => console.log(`Stat channel renamed to: ${newChannel.name}`))
.catch(console.error);
}, 30000)
}
module.exports = {
updateStats
}
function updateStats(client) {
const Discord = require('discord.js');
const config = require("../settings/configuration");
const settings = require("../settings/configuration");
const guild = client.guilds.cache.get(settings.BOT_SETTINGS.Guild_ID);
const totalUsers = client.channels.fetch('883654989271154728');
const onlineUsers = client.channels.fetch('883655041813200926');
setInterval(function() {
const interval = (async function() {
for await (const startTime of setInterval(interval, Date.now())) {
const now = Date.now();
console.log(now);
if ((now - startTime) > 1000)
break;
}
console.log(Date.now());
})();
console.log('Getting stats update..')
var userCount = guild.memberCount;
var onlineCount = guild.members.filter(m => m.presence.status === 'online').size
console.log("Total Users: " + userCount);
console.log("Online Users: " + onlineCount);
totalUsers.setName("Total Users: " + userCount)
.then(newChannel => console.log(`Stat channel renamed to: ${newChannel.name}`))
.catch(console.error);
onlineUsers.setName("Online Users: " + onlineCount)
.then(newChannel => console.log(`Stat channel renamed to: ${newChannel.name}`))
.catch(console.error);
}, 30000)
}
module.exports = {
updateStats
}
2 Replies
d.js toolkit
d.js toolkit12mo 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
≪ °✾° ≫ 𝓓𝓮𝓵𝓽𝓪_𝓑𝓻𝓪𝓿𝓸92 ≪ °✾° ≫
Error:
Getting stats update..
[Error] An exception happened in process:
TypeError: Cannot read property 'memberCount' of undefined
at Timeout._onTimeout (/home/container/events/Stats.js:19:29)
at listOnTimeout (internal/timers.js:554:17)
at processTimers (internal/timers.js:497:7)
[Error] An error happened in process:
ReferenceError: Cannot access 'interval' before initialization
at /home/container/events/Stats.js:10:51
at Timeout._onTimeout (/home/container/events/Stats.js:17:9)
at listOnTimeout (internal/timers.js:554:17)
at processTimers (internal/timers.js:497:7)
Getting stats update..
[Error] An exception happened in process:
TypeError: Cannot read property 'memberCount' of undefined
at Timeout._onTimeout (/home/container/events/Stats.js:19:29)
at listOnTimeout (internal/timers.js:554:17)
at processTimers (internal/timers.js:497:7)
[Error] An error happened in process:
ReferenceError: Cannot access 'interval' before initialization
at /home/container/events/Stats.js:10:51
at Timeout._onTimeout (/home/container/events/Stats.js:17:9)
at listOnTimeout (internal/timers.js:554:17)
at processTimers (internal/timers.js:497:7)
Yeah, I know that and that’s my next project; i was hoping to have a fully functional file to update first though instead of trying to fix and update simultaneously since I’m going to have the V12 bot running whilst I update to V14 Yeah, I gathered. I started updating about 2 years ago, then fell really unwell so need to start over now. Thank you for responding, though... time to do a massive overhaul I guess! <<NOT SOLVED BUT CLOSING AS NO LONGER RELEVANT>>
Want results from more Discord servers?
Add your server