#Coding Amendment

7 messages · Page 1 of 1 (latest)

iron vector
#

Hey guys,
I'm getting multiple errors (available if needed) in a specific file, but they all seem to relate to my ```js
var userCount = guild.memberCount;

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:
```js
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
    }
merry minnowBOT
#
  • What's your exact discord.js npm list discord.js and node node -v version?
  • 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
iron vector
#

Error:

[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)```
sweet epoch
#

v12 is no longer supported and has been deprecated for a long time now. Update is inevitable

iron vector
#

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

sweet epoch
iron vector