messageDelete events can't read "id" of the user(message author)

client.on('messageDelete', async (messageDelete) => {

const fetchedLogs = await messageDelete.guild.fetchAuditLogs({
limit: 6,
type: 'MESSAGE_DELETE'
}).catch(console.error);

const auditEntry = fetchedLogs.entries.find(a =>
a.target.id === messageDelete.author.id && // error ("id")
a.extra.channel.id === messageDelete.channel.id &&
Date.now() - a.createdTimestamp < 20000
);
const executor = auditEntry.executor ? auditEntry.executor.tag : 'Unknown';

const DeleteEmbed = new Discord.MessageEmbed()
.setTitle("DELETED MESSAGE")
.setColor("#fc3c3c")
.addField("Author", messageDelete.author.tag, true)
.addField("Deleted By", executor, true)
.addField("Channel", messageDelete.channel, true)
.addField("Message", messageDelete.content || "None")
.setFooter(`Message ID: ${messageDelete.id} | Author ID: ${messageDelete.author.id}`);

const DeleteChannel = messageDelete.guild.channels.find(x => x.name === "delete-log");
DeleteChannel.send(DeleteEmbed);
})
client.on('messageDelete', async (messageDelete) => {

const fetchedLogs = await messageDelete.guild.fetchAuditLogs({
limit: 6,
type: 'MESSAGE_DELETE'
}).catch(console.error);

const auditEntry = fetchedLogs.entries.find(a =>
a.target.id === messageDelete.author.id && // error ("id")
a.extra.channel.id === messageDelete.channel.id &&
Date.now() - a.createdTimestamp < 20000
);
const executor = auditEntry.executor ? auditEntry.executor.tag : 'Unknown';

const DeleteEmbed = new Discord.MessageEmbed()
.setTitle("DELETED MESSAGE")
.setColor("#fc3c3c")
.addField("Author", messageDelete.author.tag, true)
.addField("Deleted By", executor, true)
.addField("Channel", messageDelete.channel, true)
.addField("Message", messageDelete.content || "None")
.setFooter(`Message ID: ${messageDelete.id} | Author ID: ${messageDelete.author.id}`);

const DeleteChannel = messageDelete.guild.channels.find(x => x.name === "delete-log");
DeleteChannel.send(DeleteEmbed);
})
2 Replies
d.js toolkit
d.js toolkit2y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
Pooyan
PooyanOP2y ago
Client:
const Discord = require("discord.js");
const client = new Discord.Client({
intents: 32767,
partials: ["MESSAGE", "CHANNEL", "REACTION"]
});
const Discord = require("discord.js");
const client = new Discord.Client({
intents: 32767,
partials: ["MESSAGE", "CHANNEL", "REACTION"]
});
I'm using [email protected] and node 16.14.2 I logged messageDelete in console and it returned this (as you can see author is null idk why) :
<ref *1> Message {
channelId: '1063813039444467763',
guildId: '944616601678917632',
id: '1085555040426664016',
position: null,
createdTimestamp: 1678886890275,
system: null,
type: null,
content: null,
author: null,
pinned: null,
tts: null,
nonce: null,
embeds: [],
components: [],
attachments: Collection(0) [Map] {},
stickers: Collection(0) [Map] {},
editedTimestamp: null,
reactions: ReactionManager { message: [Circular *1] },
mentions: MessageMentions {
everyone: false,
users: Collection(0) [Map] {},
roles: Collection(0) [Map] {},
_members: null,
_channels: null,
_parsedUsers: null,
crosspostedChannels: Collection(0) [Map] {},
repliedUser: null
},
webhookId: null,
groupActivityApplication: null,
applicationId: null,
activity: null,
flags: MessageFlags { bitfield: 0 },
reference: null,
interaction: null
}
<ref *1> Message {
channelId: '1063813039444467763',
guildId: '944616601678917632',
id: '1085555040426664016',
position: null,
createdTimestamp: 1678886890275,
system: null,
type: null,
content: null,
author: null,
pinned: null,
tts: null,
nonce: null,
embeds: [],
components: [],
attachments: Collection(0) [Map] {},
stickers: Collection(0) [Map] {},
editedTimestamp: null,
reactions: ReactionManager { message: [Circular *1] },
mentions: MessageMentions {
everyone: false,
users: Collection(0) [Map] {},
roles: Collection(0) [Map] {},
_members: null,
_channels: null,
_parsedUsers: null,
crosspostedChannels: Collection(0) [Map] {},
repliedUser: null
},
webhookId: null,
groupActivityApplication: null,
applicationId: null,
activity: null,
flags: MessageFlags { bitfield: 0 },
reference: null,
interaction: null
}
What should I do now? This was working before It returned rooexcited what now? But I can't cache it, can I? So there is no hope for it anymore?
Want results from more Discord servers?
Add your server