Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

!am User not adding in user #7

Open
Driganka opened this issue Jul 15, 2022 · 6 comments
Open

!am User not adding in user #7

Driganka opened this issue Jul 15, 2022 · 6 comments

Comments

@Driganka
Copy link

TypeError: Cannot read properties of null (reading 'members')
Passing in user as !am <@user_id>

@navn-r
Copy link
Owner

navn-r commented Jul 15, 2022

Hey, thanks for putting in the issue, please output the full error (including stack trace) in the issue description, and I can take a look.

Thanks.

@Driganka
Copy link
Author

% npm run start                                                           1 ↵ ✹

> [email protected] start
> node index.js

mongoDB connected
Discord Bot Ready
TypeError: Cannot read properties of null (reading 'members')
    at /Users/driganka/Documents/NightHack/Scrum Bot/standup-bot/commands/addMember.js:28:35
    at Array.forEach (<anonymous>)
    at /Users/driganka/Documents/NightHack/Scrum Bot/standup-bot/commands/addMember.js:20:14
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at runNextTicks (node:internal/process/task_queues:65:3)
    at processImmediate (node:internal/timers:437:9)

@navn-r
Copy link
Owner

navn-r commented Jul 16, 2022

And just to confirm, do you have a .env file with DISCORD_TOKEN, and MONGO_URI? Apologies for not mentioning this in the README.

@Driganka
Copy link
Author

Driganka commented Jul 16, 2022 via email

@Fiddler46
Copy link

Fiddler46 commented Jul 17, 2022

The standup from addMember.js here is being returned as null when I tried console logging it. For some reason, the properties aren't being properly sent. I think it has to do with the guildId not being present in the standupModel.

standupModel
      .findById(message.guild.id)
      .then((standup) => {
        args.forEach((mention) => {
          if (mention.startsWith("<@") && mention.endsWith(">")) {
            mention = mention.slice(2, -1);

            if (mention.startsWith("!")) mention = mention.slice(1);

            const member = message.guild.members.cache.get(mention);
            console.log(standup);

            if (member && standup.members.indexOf(member.id) == -1)
              standup.members.push(member.id);
              console.log(standup);
          }
        });

This is the error that returns in the console:

null
TypeError: Cannot read properties of null (reading 'members')
  at /home/nero/Projects/ScrumBotDiscord/commands/addMember.js:29:35
  at Array.forEach (<anonymous>)
  at /home/nero/Projects/ScrumBotDiscord/commands/addMember.js:20:14
  at processTicksAndRejections (node:internal/process/task_queues:96:5)

Within the code, the error that returns on the server is this second catch statement right here within in addMember.js around line 50:

 standup
          .save()
          .then(() => message.channel.send("Members updated :tada:"))
          .catch((err) => {
            console.err(err);
            message.channel.send(
              "Oh no :scream:! An error occured somewhere in the matrix!"
            );
          });
      })
      .catch((err) => {
        console.error(err);
        message.channel.send(
          "Oh no :scream:! An error occured somewhere in the matrix!2222" // This one is returned 
        );
      });
  },
};

Is there someway to fix that by getting it recognise the guildId of the server before the command has been sent? @navn-r

@navn-r
Copy link
Owner

navn-r commented Jul 18, 2022

Hey @Fiddler46, thanks for the explanation.

The guild id should have been present in the database at that point, as when the bot is added to a new guild, we create a new document as shown here

bot.on("guildCreate", async (guild) => {
  //...
  
  // creates the database model
  const newStandup = new standupModel({
    _id: guild.id,
    channelId: channel.id,
    members: [],
    responses: new Map(),
  });
  
  //...
  await channel.send(standupIntroMessage);
});

So, followup question: When you add the bot to the server, do you see the standupIntroMessage embed? If not then I think re-adding the bot could fix this. If you do see it, then yea, I suspect there's some problem with the guildCreate.

Unfortunately I'm quite busy at the moment, so I do not have time to investigate further. It would be great if anyone could take this and submit a PR. I'd be happy to review it.

Please let me know if there are other questions regarding this issue, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants