0
votes

I am trying to set up a warn command that pushes the warn info on a per server basis to my database. However ... it doesn't like that idea


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

1 Answers

0
votes

Errors seems to be triggered by this string user.warns.ensure(key, []) , where warns field of user is undefined. try adding this strings before user.warns.ensure(key, [])

console.log(user.warns)

to see, if warns object is present in user object.

If its not present, you need to define warns. Since there is function .ensure(key, []), its probably has more complicated structure