TransWikia.com

(node:4468) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'guild' of undefined Discord.js

Stack Overflow Asked by TalentYT on January 1, 2021

I was following a tutorial on modlog channel but i keep getting this error.

(node:4468) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'guild' of undefined

Here is the code

client.on('messageDelete', async (client, message) => {
    if (message.partial) await message.fetch();

    let modlog = db.get(`moderation.${message.guild.id}.modlog`);
    if (!modlog) return;

    if (message.channel.id === modlog.channel) return;

    let toggle = modlog.toggle;
    if (!toggle || toggle == null || toggle == false) return;

    const embed = new MessageEmbed()
    .setTitle("Message Deleted")
    .setDescription(`Message deleted in <#${message.channel.id}> by **${message.author.tag}** n> ${message.content}`)

    return message.guild.channels.cache.get(modlog.channel).send(embed);
})

One Answer

The Client#messageDelete event gives you only the Message as the first argument. The second argument is undefined.


client.on("messageDelete", async (message) => {
    if (message.partial) await message.fetch();

    let modlog = db.get(`moderation.${message.guild.id}.modlog`);
    if (!modlog) return;

    if (message.channel.id === modlog.channel) return;

    let toggle = modlog.toggle;
    if (!toggle || toggle == null || toggle == false) return;

    const embed = new MessageEmbed().setTitle("Message Deleted").setDescription(`Message deleted in <#${message.channel.id}> by **${message.author.tag}** n> ${message.content}`);

    return message.guild.channels.cache.get(modlog.channel).send(embed);
});

Correct answer by Jakye on January 1, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP