Why discord.js ?.command.set(command) don't works?

Viewed 26

I was developing a discord bot and I was wrong to register a slash commands and I wanted to overwrite it with the .set function but it gave me an error in a file that I had not edited.

index.js code:

client.on('messageCreate', async (message) =>{

    if(message.content.toLowerCase() === "lava.register"){
        const data = {
            name: "ban",
            description: "Banna un utente dal server",
            option: [
                {
                    name: "UTENTE",
                    description: "Specifica l\'utente da bannare dal server",
                    type: "USER",
                    require: true,
                },
                {
                    name: "MOTIVO",
                    description: "Specifica il motivo del ban",
                    type: "STRING",
                    require: true,
                }
            ]
        }; 

        const comando = await client.guilds.cache.get('957317299289858108')?.commands.set(data);
        console.log(comando)
    }
})

error:

data: commands.map(c => this.constructor.transformCommand(c)),
                     ^

TypeError: commands.map is not a function
    at GuildApplicationCommandManager.set (/Users/Me/Desktop/VolcanoBot/node_modules/discord.js/src/managers/ApplicationCommandManager.js:157:22)
    at Client.<anonymous> (/Users/yihanzhou/Desktop/VolcanoBot/index.js:35:87)
    at Client.emit (node:events:537:28)
    at MessageCreateAction.handle (/Users/yihanzhou/Desktop/VolcanoBot/node_modules/discord.js/src/client/actions/MessageCreate.js:26:14)
    at module.exports [as MESSAGE_CREATE] (/Users/yihanzhou/Desktop/VolcanoBot/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
    at WebSocketManager.handlePacket (/Users/yihanzhou/Desktop/VolcanoBot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:346:31)
    at WebSocketShard.onPacket (/Users/yihanzhou/Desktop/VolcanoBot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:478:22)
    at WebSocketShard.onMessage (/Users/yihanzhou/Desktop/VolcanoBot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:317:10)
    at WebSocket.onMessage (/Users/yihanzhou/Desktop/VolcanoBot/node_modules/ws/lib/event-target.js:199:18)
    at WebSocket.emit (node:events:537:28)

the file (VolcanoBot/node_modules/discord.js/src/managers/ApplicationCommandManager.js:157:22)

async set(commands, guildId) {
    const data = await this.commandPath({ guildId }).put({
      data: commands.map(c => this.constructor.transformCommand(c)),
    });
    return data.reduce((coll, command) => coll.set(command.id, this._add(command, true, guildId)), new Collection());
  }

What should I do?

0 Answers
Related