我尝试以这种方式添加命令权限,只有具有特定 Angular 色的用户才能使用它。首先,我创建了像文档中所述的命令。
然后我尝试获取每个命令并向其添加新权限:
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);
});
但无论我做什么,我都会收到此错误:TypeError [INVALID_TYPE]:提供的权限不是 ApplicationCommandPermissionData 数组。
我也尝试按照文档中所示运行此代码,但得到了相同的结果:
await commands.forEach(command => {
...
console.log(`Changing command ${command.id}`);
command.permissions.add({permissions2});
command.permissions.add({permissions1});
});
最佳答案
将代码更改为此有帮助:
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]
});
});
关于javascript - Discord.js。无法为斜杠命令添加权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68731446/