我正在尝试设置一个警告命令,该命令将每个服务器的警告信息推送到我的数据库。但是...不喜欢这个想法
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)
}
答案 0 :(得分:0)
错误似乎由此字符串user.warns.ensure(key, [])
触发,其中user warns
字段未定义。尝试在user.warns.ensure(key,[])
console.log(user.warns)
查看用户对象中是否存在警告对象。
如果不存在,则需要定义警告。
由于存在函数.ensure(key, [])
,它的结构可能更复杂