UnhandledPromiseRejectionWarning:TypeError:无法设置未定义的属性”

时间:2019-01-01 14:19:58

标签: node.js

因此,我正在尝试创建一个函数来警告用户并将其写入JSON文件。但是,当我尝试使用命令时,出现错误:

  

“无法设置未定义的属性'(discord用户ID)'”。

我已经在另一个命令中执行了相同的代码,并且它运行得很好,所以我很困惑。

const fs = module.require("fs");

module.exports.run = async (bot, message, args) => {
    let toWarn = message.guild.member(message.mentions.users.first()) || message.guild.members.get(args[0]);
    if(!toWarn) return message.channel.send("You did not specify a user mention or ID.");

    if(toWarn.id === message.author.id) return message.channel.send("You cannot mute yourself.");
    if(toWarn.highestRole.position >= message.member.highestRole.position) return message.channel.send("You cannot warn someone with an equal or higher role.");

    bot.warns[toWarn.id] = {
        guild: message.guild.id,
        reason: args
    };

    fs.writeFile("./warns.json", JSON.stringify(bot.warns, null, 4), err => {
        if(err) throw err;
        message.channel.send("I have warned the user.");
    });
}
module.exports.help = {
    name: "warn"
}

调试显示bot.warns部分存在错误。我正在使用VS Code,如果有帮助的话。预先感谢您,并感谢您修复代码块。

0 个答案:

没有答案