Please describe the problem you are having in as much detail as possible:
According to https://discord.js.org/#/docs/main/stable/class/GuildAuditLogsEntry there are two properties available: createdAt and createdTimestamp. However, neither of these actually exist in the GuildAuditLogsEntry object.
Include a reproducible code sample here, if possible:
bot.on("guildMemberRemove", (member) => {
member.guild.fetchAuditLogs({ limit: 1 }).then(logs => {
var logArray = Array.from(logs.entries.values());
var entry = logArray[0];
console.log(entry);
}).catch(console.error);
});
Further details:
They are getters so they will not be listed when the object is serialized. I assure you that they exist however.
Then is Array.from() removing them? Because I'm using the console.log in that code as an example for you guys. When I actually try to access those values elsewhere, I get errors because they return undefined.
EDIT: Here, try this then:
bot.on("guildMemberRemove", (member) => {
member.guild.fetchAuditLogs({ limit: 1 }).then(logs => {
var logArray = Array.from(logs.entries.values());
var entry = logArray[0];
member.guild.channels.find("name", "general").send(entry.createdTimestamp).catch(console.error);
}).catch(console.error);
});
This gives me undefined errors because entry.createdTimestamp does not exist.
message.guild.fetchAuditLogs({ limit: 1 }).then(logs => {
message.channel.send(logs.entries.first().createdTimestamp)
});
works fine for me
P.S. i would filter the audit logs by member.user to prevent race conditions
Both GuildAuditLogsEntry properties createdAt and createdTimestamp are undefined for me, all others are defined. I notice they are the only two GuildAuditLogsEntry properties that are marked READ-ONLY but that should not matter. If anyone knows what I am doing wrong, please advise. I am using the following versions:
node.js: 6.10.3
discord.js 11.1.0
Ubuntu: 14.04.5 LTS
Code:
client.on('guildMemberRemove', member => {
let guild = member.guild;
member.guild.fetchAuditLogs({
limit: 1
}).then(logs => {
var logArray = Array.from(logs.entries.values());
console.log("createdTimestamp: " + logArray[0].createdTimestamp);
console.log("createdAt: " + logArray[0].createdAt);
// try alternative way
console.log("createdTimestamp: " + logs.entries.first().createdTimestamp);
console.log("createdAt: " + logs.entries.first().createdAt);
}).catch(console.error);
});
Console Output:
createdTimestamp: undefined
createdAt: undefined
createdTimestamp: undefined
createdAt: undefined
I checked my GuildAuditLogs.js file and it did not contain those properties. I was using 11.1.0, which was the latest available using npm update discord.js. I tried npm update hydrabolt/discord.js to get master from Github and it installed 12.0.0 and the GuildAuditLogs.js now has those properties and so no longer returns undefined.
Confirmed, this is fixed at the moment in 12.0.0-dev after doing npm i hydrabolt/discord.js. Thanks @MorningSleeper!
createdAt()
@Xeron1 This was already resolved in my last reply posted _a year and a half ago._
Most helpful comment
Then is
Array.from()removing them? Because I'm using theconsole.login that code as an example for you guys. When I actually try to access those values elsewhere, I get errors because they returnundefined.EDIT: Here, try this then:
This gives me
undefinederrors becauseentry.createdTimestampdoes not exist.