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 toolkit13mo 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
KayOP13mo 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
ayman13mo ago
What’s does Guild return ?
Kay
KayOP13mo ago
undefined
treble/luna
treble/luna13mo ago
show your event handler
ayman
ayman13mo ago
Yeah probably the event handler
Kay
KayOP13mo 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
ayman13mo ago
Seems good to me What does guildAuditLogEntry returns ?
Kay
KayOP13mo ago
exactly what you would expect
space
space13mo 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
KayOP13mo 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
Want results from more Discord servers?
Add your server