Estoy tratando de agregar permiso a los comandos de tal manera que solo los usuarios con un rol específico puedan usarlo. Al principio estoy creando comandos como se dice en la documentación.
Luego estoy tratando de obtener cada comando y agregarles nuevos permisos:
await commands.forEach(command => { const permissions2 = [ { id: guild.roles.everyone.id, type: 'ROLE', permission: false, } ]; const permissions1 = [ { id: botRole.id, type: 'ROLE', permission: true, }, ]; console.log(`Changing command ${command.id}`); command.permissions.add(permissions2); command.permissions.add(permissions1); }); Pero haga lo que haga, aparece este error: TypeError [INVALID_TYPE]: Supplied permissions is not an Array of ApplicationCommandPermissionData. También intenté ejecutar este código como se muestra en la documentación, pero obtuve el mismo resultado:
await commands.forEach(command => { ... console.log(`Changing command ${command.id}`); command.permissions.add({permissions2}); command.permissions.add({permissions1}); });Cambiar el código a esto ayudó:
const permissions2 = { id: guild.roles.everyone.id, type: 'ROLE', permission: false, }; const permissions1 = { id: botRole.id, type: 'ROLE', permission: true, }; let commandsList = await guild.commands.fetch(); await commandsList.forEach(slashCommand => { console.log(`Changing command ${slashCommand.id}`); //set the permissions for each slashCommand guild.commands.permissions.add({ command: slashCommand.id, permissions: [permissions1, permissions2] }); });No creo que puedas usar el bucle forEach como lo hiciste.
commands.permissions#set consta de un objeto con la identificación del comando que desea editar y una matriz con los permisos.
Así que tendrías que volver a escribir tu código a esto:
//create the permissions objects const permissions2 = { id: guild.roles.everyone.id, type: 'ROLE', permission: false, }; const permissions1 = { id: botRole.id, type: 'ROLE', permission: true, }; //loop through all the slashCommands await commands.forEach(slashCommand => { console.log(`Changing command ${slashCommand.id}`); //set the permissions for each slashCommand client.application.commands.permissions.set({command: slashCommand.id, permissions: [permissions1, permissions2]}); });Lea más sobre la configuración de permisos para slashCommands aquí