Need Help for Fetch Ban CreatedAt

const { Events } = require('discord.js')

module.exports = async (client) => {


    // UNBAN COMMAND
    client.on(Events.InteractionCreate, async (interaction) => {
        if (!interaction.isAutocomplete()) return;
        if (interaction.commandName !== 'server') return;

        const guild = interaction.guild;
        if (!guild) return; // Make sure interaction is within a guild
        
        try {
            await guild.members.fetch(); // Make sure all guild members are cached
            const bans = await guild.bans.fetch() // Fetch bans from the guild
            const focusedValue = interaction.options.getFocused();

            let filteredBans;
            if (!isNaN(focusedValue)) {
                // If the input is a number, search by ID
                filteredBans = bans.filter(ban => 
                    ban.user.id.includes(focusedValue));
            } else {
                // Otherwise, search by username and reason
                filteredBans = bans.filter(ban => {
                    const user = ban.user;
                    return user.username.toLowerCase().startsWith(focusedValue.toLowerCase()) ||
                           (ban.reason && ban.reason.toLowerCase().includes(focusedValue.toLowerCase()));
                });
            }
  
            const results = filteredBans.map(ban => ({
                name: `${ban.user.tag} - ${ban.user.id} - ${ban.reason  ?? 'Kein Grund angegeben'} - ${new Date(ban.createdAt).toLocaleString()}`,
                value: ban.user.id
            }));

            interaction.respond(results.slice(0, 25)).catch(() => {});
        } catch (error) {
            console.error('Error fetching bans:', error);
            interaction.respond({ content: 'An error occurred while fetching bans.', ephemeral: true }).catch(() => {});
        }
    });


}

I have a problem with the
${new Date(ban.createdAt).toLocaleString()}

its respons with "Invalid Date" and i dont now how to get the ban date on other ways, can someone help me?
Screenshot_2024-03-04_163903.png
Was this page helpful?