naatthhaan
naatthhaan
DIAdiscord.js - Imagine an app
Created by naatthhaan on 10/13/2024 in #djs-questions
Get user who deleted a message
On the messageDelete event, is there any way to get the user who deleted the message? I'm trying with audit logs but its not giving anything relevant:
const { EmbedBuilder, AuditLogEvent } = require("discord.js");

module.exports = {
once: false,
async execute(message, client) {
if (message.partial) {
try {
message = await message.fetch();
} catch {
return;
}
}
if (message.author.bot) return;

const embed = new EmbedBuilder()
.setTitle("Message Deleted")
.setDescription(`**${message.author.toString()}**'s message was deleted in <#${message.channel.id}>`)
.setColor(client.config.colors.danger)
.addFields({
name: "Content",
value: message.content || "No content",
inline: false,
})
.setFooter({
text: client.config.footer.text,
iconURL: client.config.footer.img,
})
.setTimestamp();

let channel = await client.channels.fetch(client.config.channels.memberChannel);

const fetchedLogs = await message.guild.fetchAuditLogs({
limit: 1,
type: AuditLogEvent.MessageDelete,
});
const deletionLog = fetchedLogs.entries.first();

if (deletionLog) {
const { executor, target, createdAt } = deletionLog;

const timeDifference = Date.now() - createdAt.getTime();
const isSameMessage = target.id === message.author.id;

if (isSameMessage && timeDifference < 5000) {
embed.addFields({
name: "Deleted by",
value: executor.tag,
inline: true,
});
}
}

channel.send({ embeds: [embed] });
},
};
const { EmbedBuilder, AuditLogEvent } = require("discord.js");

module.exports = {
once: false,
async execute(message, client) {
if (message.partial) {
try {
message = await message.fetch();
} catch {
return;
}
}
if (message.author.bot) return;

const embed = new EmbedBuilder()
.setTitle("Message Deleted")
.setDescription(`**${message.author.toString()}**'s message was deleted in <#${message.channel.id}>`)
.setColor(client.config.colors.danger)
.addFields({
name: "Content",
value: message.content || "No content",
inline: false,
})
.setFooter({
text: client.config.footer.text,
iconURL: client.config.footer.img,
})
.setTimestamp();

let channel = await client.channels.fetch(client.config.channels.memberChannel);

const fetchedLogs = await message.guild.fetchAuditLogs({
limit: 1,
type: AuditLogEvent.MessageDelete,
});
const deletionLog = fetchedLogs.entries.first();

if (deletionLog) {
const { executor, target, createdAt } = deletionLog;

const timeDifference = Date.now() - createdAt.getTime();
const isSameMessage = target.id === message.author.id;

if (isSameMessage && timeDifference < 5000) {
embed.addFields({
name: "Deleted by",
value: executor.tag,
inline: true,
});
}
}

channel.send({ embeds: [embed] });
},
};
8 replies
DIAdiscord.js - Imagine an app
Created by naatthhaan on 8/22/2024 in #djs-voice
Trying to record VC but the out file is static
everything works as expect in the console but the out .pmc when converted is only a short clip of static.
7 replies