此错误是一个奇怪的错误,因为该代码有效:它使用Administrator标志创建了一个管理员角色。最重要的是: 该机器人位于ADMIN角色之上,并且是管理员。
创建角色时出现错误。该错误表明缺少权限,但是成功创建了ADMIN角色,因此它没有失败。还有另一件事:当我忽略位置参数时,它工作正常,完全没有错误。但不幸的是,我需要position参数,因为我想添加更多角色。我在这里想念什么?
bot.on('ready', () => {
const ids = bot.guilds.cache.map(guild => guild.id);
// Checks if the necessary roles are present on every guild, creates them if they are not there.
for (const id of ids) {
let guild = bot.guilds.cache.get(id);
async function assignRoles() {
let adminRole = guild.roles.cache.find(role => role.name === "ADMIN") ? console.log("Role ADMIN is present at " + '\x1b[36m%s\x1b[0m%s', guild.name, ".") : guild.roles.create({
data:{
name:"ADMIN",
color:"GREEN",
hoist: true,
position: 2,
permissions: ["ADMINISTRATOR"]
},
reason:"The administrator role.",
}).then(console.log("Created the necessary role ADMIN at " + '\x1b[35m%s\x1b[0m%s', guild.name, "."))
let allRole = await adminRole; // + await mutedRole + await friendRole
return allRole;
}
assignRoles();
}
}