0

I switched to mongoose not too long ago from rethinkdb, and i have re-coding most of the things of course. And i keep getting this error spammed TypeError: Cannot read property 'logsChannel' of undefined at Trinity.exports.handle (/home/ubuntu/Trinity/src/events/guildMemberAdd.js:5:22)

and it spams it a lot, and it errors for my other events as well.

const Guild  = require('../db/models/Guild');

exports.handle = async function (guild, member) {   
    let logs = await Guild.findOne({ guildID: guild.id })
    if(logs.lchannel.logsChannel.enabled == false) return;
    this.bot.createMessage(logs.lchannel.logsChannel.channelID, {
        embed: {
            author: {
                name: `${member.username}#${member.discriminator}`,
                icon_url: member.avatarURL
            },
            color: 0x2196F3,
            timestamp: new Date(),
            fields: [
                {
                    name: "Member Joined",
                    value: `**${member.username}** has joined **${guild.name}**`
                }
            ]
        }
    }).catch(err => { });


that is my code.
ETLegacy
  • 35
  • 1
  • 8
  • Pretty obvious question but have you checked that the logs object really contains the lchannel and logsChannel parameters? – Morta1 Jul 25 '21 at 06:45
  • You should first console.log your logs and check wether it has Ichannel and logsChannel. – Arvind Pal Jul 25 '21 at 07:20
  • @Morta1 sorry for delay, i did console log and it logged nothing. Thing is, the code works, but still spams though, it would send the event, but still error? – ETLegacy Jul 27 '21 at 11:03
  • If logs is undefined then It seems like the server you're trying to find doesn't exist, maybe the id is wrong? – Morta1 Jul 27 '21 at 11:28
  • @Morta1 pretty weird, as it adds the server id to the database, and it has to check for it's enabled. I'm happy to send my logs command (that sets up this thing) if that will help more. – ETLegacy Aug 01 '21 at 10:45

0 Answers0