Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

129
Views
Cannot read property 'author' of undefined

I use the events folder and would like to have logs to delete messages.

But unfortunately I get this error when someone deletes a message:

TypeError: cannot read property 'author' of undefined

Does anyone know what to do about this please?

Code:

const Discord = require('discord.js') 

module.exports = async(guild, interaction, user, client, message, messageDelete, author) => {

  let DeleteEmbed = new Discord.MessageEmbed()
  .setTitle("**SMAZANÁ ZPRÁVA**")
  .setColor("#fc3c3c")
  .addField(`Autor:`, `${message.author.tag}`, true)
  .addField(`Kanál:`, `${message.channel}`, true)
  .addField(`Zpráva:`, `${message.content}`);

  let DeleteChannel = client.channels.cache.get("969632261446176848").send({embeds: [DeleteEmbed]});
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You get your error because message is undefined. Simply check your function inputs before adding the related fields:

const Discord = require('discord.js') 

module.exports = async(guild, interaction, user, client, message, messageDelete, author) => {

  let DeleteEmbed = new Discord.MessageEmbed()
  .setTitle("**SMAZANÁ ZPRÁVA**")
  .setColor("#fc3c3c");
  if (message && message.author)
    DeleteEmbed.addField(`Autor:`, `${message.author.tag}`, true)
  if (message && message.channel)
    DeleteEmbed.addField(`Kanál:`, `${message.channel}`, true)
  if (message && message.content)
    DeleteEmbed.addField(`Zpráva:`, `${message.content}`);

  let DeleteChannel = client.channels.cache.get("969632261446176848").send({embeds: [DeleteEmbed]});
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!