Import all commands from folder with ES modules

So my previous bot I build I used CommonJS and did the commands like this:
const commandsList = [];
const slashCommandFiles = readdirSync(path.resolve(__dirname, '../discord/commands'));

for (const fileSlash of slashCommandFiles) {
    const commandSlash = require(path.resolve(__dirname, `../discord/commands/${fileSlash}`));
    commandsList.push(commandSlash.commands)
}

But now I really prefer to work with ES modules also because they are by default async.
But now I have been thinking about a way to import all commands from the folder. But it doesn't work that easy with import.
Anyone know a good way to do this.
Because the export where build like
{
  data: blabla,
  action: (arg) => { stuff }
}
Was this page helpful?