(节点:7528)UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性“确保”

时间:2019-08-07 17:07:21

标签: javascript discord.js

我正在尝试设置一个警告命令,该命令将每个服务器的警告信息推送到我的数据库。但是...不喜欢这个想法


module.exports.run = async(client, message, args) => {


  const Discord = require('discord.js')
  if(!message.member.roles.find(r => r.name === 'moderator')) return message.channel.send(`You do not have the power to control meh! ||(need a role named "moderator") for testing purposes||`)
  let user = message.mentions.users.first()
  if(!user) return message.channel.send('Who do you want to warn?')
  let reason = args.slice(1).join(' ')
  if(!reason) return message.channel.send('Why is this person being warned?')
  const key = user.id

  user.warns.ensure(key, [])
  user.warns.push(key, { reason: reason, moderator: message.author.id, caseNum: user.warns.size + 1 ,date: new Date() })
  let warnedEmbed = new Discord.RichEmbed()
    .setTitle('L\'user' + user.tag + 'has been warned!')
    .addField('Reason being', reason)
  const cm = await message.channel.send(warnedEmbed)
  cm.delete(5000)
}

1 个答案:

答案 0 :(得分:0)

错误似乎由此字符串user.warns.ensure(key, [])触发,其中user warns字段未定义。尝试在user.warns.ensure(key,[])

之前添加此字符串
console.log(user.warns)

查看用户对象中是否存在警告对象。

如果不存在,则需要定义警告。 由于存在函数.ensure(key, []),它的结构可能更复杂