GuildAuditLogEntryCreate does not provide a guild

in the documentation it says that the GuildAuditLogEntryCreate event a guild provides. but it seems to always be undefined the guildAuditLogsEntry does exist but i cant seem to get a guild value from that somehow https://old.discordjs.dev/#/docs/discord.js/main/class/Client?scrollTo=e-guildAuditLogEntryCreate
Discord.js
Discord.js is a powerful node.js module that allows you to interact with the Discord API very easily. It takes a much more object-oriented approach than most other JS Discord libraries, making your bot's code significantly tidier and easier to comprehend.
11 Replies
d.js toolkit
d.js toolkit7mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
Kay
Kay7mo ago
code:
import DiscordClient from "../utils/client.ts";
import Database from "../utils/database.ts";
import Event from "../utils/structures/Event.ts"
import { Events, Guild, GuildAuditLogsEntry } from "npm:discord.js";

export default class ReadyEvent extends Event {

constructor() {
super(Events.GuildAuditLogEntryCreate, true);
}

async execute(client: DiscordClient, entry: GuildAuditLogsEntry, guild: Guild): Promise<void> {

console.log(entry) // logs the Entry
console.log(guild) // Logs 'undefined'

// const db = new Database("database.db")

// const dbGuild = db.getGuild(guild.id);

// if (dbGuild?.config.logChannel == null) return;

// let channel = await guild.channels.fetch(dbGuild.config.logChannel);
// if (!channel || !channel?.isTextBased()) return;
// channel.send(JSON.stringify(entry));

}

}
import DiscordClient from "../utils/client.ts";
import Database from "../utils/database.ts";
import Event from "../utils/structures/Event.ts"
import { Events, Guild, GuildAuditLogsEntry } from "npm:discord.js";

export default class ReadyEvent extends Event {

constructor() {
super(Events.GuildAuditLogEntryCreate, true);
}

async execute(client: DiscordClient, entry: GuildAuditLogsEntry, guild: Guild): Promise<void> {

console.log(entry) // logs the Entry
console.log(guild) // Logs 'undefined'

// const db = new Database("database.db")

// const dbGuild = db.getGuild(guild.id);

// if (dbGuild?.config.logChannel == null) return;

// let channel = await guild.channels.fetch(dbGuild.config.logChannel);
// if (!channel || !channel?.isTextBased()) return;
// channel.send(JSON.stringify(entry));

}

}
ayman
ayman7mo ago
What’s does Guild return ?
Kay
Kay7mo ago
undefined
treble/luna
treble/luna7mo ago
show your event handler
ayman
ayman7mo ago
Yeah probably the event handler
Kay
Kay7mo ago
async events(): Promise<void> {
for (const entry of walkSync(this.client.root + "\\src\\events", {includeDirs: false, exts: [".ts"]})) {
const file = await import("file://" + entry.path);
const event: Event = new file.default();
if (event.once == true) this.client.once(event.event, (...args: any[]) => {event.execute(this.client, args)});
else this.client.on(event.event, (...args: any[]) => {event.execute(this.client, ...args)});
}
}
async events(): Promise<void> {
for (const entry of walkSync(this.client.root + "\\src\\events", {includeDirs: false, exts: [".ts"]})) {
const file = await import("file://" + entry.path);
const event: Event = new file.default();
if (event.once == true) this.client.once(event.event, (...args: any[]) => {event.execute(this.client, args)});
else this.client.on(event.event, (...args: any[]) => {event.execute(this.client, ...args)});
}
}
ayman
ayman7mo ago
Seems good to me What does guildAuditLogEntry returns ?
Kay
Kay7mo ago
exactly what you would expect
space
space7mo ago
Would you? :P It's an array containing an GuildAuditLogsEntry and a Guild. Looks like you forgot the ... before args in your command handler in the once branch. (You seemingly forgot to change the parameter to the parent class to false in the handler's constructor and probably want to rename the class too)
Kay
Kay7mo ago
oh thx. yhea i missed that. it also seems that i set once to true in the event. prob cous i copied the ready event. this fixed it. thx