Не работает await в discord js

module.exports = (Client) => {
    console.log('client is connected', Client.user.tag)

    const commandArgs = process.argv.find(arg => arg.startsWith('local=') || arg === "global")

    if (commandArgs) {
        const commands = [...Client.commands].map(x => x[1].data)

        if (commandArgs.startsWith("local")) {
            await Client.guilds.fetch(commandArgs.split('=')[1]).than(async guild => await guild.commands.set(commands))
            return console.log('[!] Commands have been set locally')
        } else {
            await Client.application.commands.set(commands)
            return console.log('[!] Commands have been set globally')
        }
    }
}

Ответы (1 шт):

Автор решения: SwaD

await работает только в асинхронных функциях, объявленных через async

Сделайте вот так и у вас должно все заработать

module.exports = async (Client) => {
    console.log('client is connected', Client.user.tag)

    const commandArgs = process.argv.find(arg => arg.startsWith('local=') || arg === "global")

    if (commandArgs) {
        const commands = [...Client.commands].map(x => x[1].data)

        if (commandArgs.startsWith("local")) {
            await Client.guilds.fetch(commandArgs.split('=')[1]).than(async guild => await guild.commands.set(commands))
            return console.log('[!] Commands have been set locally')
        } else {
            await Client.application.commands.set(commands)
            return console.log('[!] Commands have been set globally')
        }
    }
}
→ Ссылка