(节点:4468)UnhandledPromiseRejectionWarning:TypeError:无法读取未定义Discord.js的属性“行会”

时间:2020-10-22 06:53:08

标签: javascript discord discord.js

我正在关注modlog频道上的教程,但我一直收到此错误。

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

这是代码

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);
})

1 个答案:

答案 0 :(得分:2)

Client#messageDelete事件只为您提供Message作为第一个参数。第二个参数是未定义的。


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);
});