'ban.reason is undefined when fetched from audit logs discord.js

ban.reason returns undefined even though there is a reason that was given and it is able to be seen in the server audit log.

this is what i have:

client.on('guildBanAdd', async ban => {
    const fetchedLogs2 = await ban.guild.fetchAuditLogs({
        limit: 1,
        type: 'MEMBER_BAN_ADD',
    });

    const banLog = fetchedLogs2.entries.first();
    if (!banLog) return console.log(`${ban.user.tag} was banned from ${ban.guild.name} but no audit log could be found.`);

    const { executor, target } = banLog;

    if (target.id === ban.user.id) {
            console.log(`${ban.user.tag} got hit with the swift hammer of justice in the guild ${ban.guild.name}, wielded by the mighty ${executor.tag}, for "${ban.reason}"`);
    } else {
        console.log(`${ban.user.tag} got hit with the swift hammer of justice in the guild ${ban.guild.name}, audit log fetch was inconclusive.`);
    }
});

this is the output:

usertag got hit with the swift hammer of justice in the guild guildname, wielded by the mighty moderatortag, for "undefined"

how can i fix this error?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source