Search code examples
javascriptdiscorddiscord.js

How to set a maximum message character limit in discord.js


I have a server and i don't want users to send long messages at all. So here is my current version of code:


client.on('message', message => {
  if (message.member.hasPermission("ADMINISTRATOR")) return;
  let sChannel = message.guild.channels.find(c => c.name === "guard-log");
  if(!sChannel) return
    let embed = new Discord.RichEmbed()
      .setTitle(`${message.author.username} tarafından gönderilen bir mesaj silindi`)
      .setDescription(`${message.content}`)
      .setTimestamp() //.toLowerCase.replace(/ /g, '').trim() 
    if(message.length > 100){ return message.delete()
  message.channel.send(`${message.author.nickname} spam is disabled!`).then(message => message.delete(10000))}
      sChannel.send(embed)
});```

Solution

  • message is the entire Message object. You need to be measuring the length of the content property of the message object.

    if (message.content.length < 100) return message.delete()