I am trying to create roles in my server via my bot in a certain order, but every time i run the command the role positions are all wrong.
Code:
client.on("message", message => {
if(message.content.startsWith(prefix + "createrole")){
message.guild.roles.create({
data: {
name: "Owner",
color: "BLUE",
position: 1
}
})
.then(role => console.log(red(`Role created`)))
.catch(err => console.log(err))
message.guild.roles.create({
data: {
name: "Admin",
color: "BLUE",
position: 2
}
})
.then(role => console.log(red(`Role created`)))
.catch(err => console.log(err))
message.guild.roles.create({
data: {
name: "Mod",
color: "BLUE",
position: 3
}
})
.then(role => console.log(red(`Role created`)))
.catch(err => console.log(err))
}
})
In Theory this should be in order but I am not sure what is going on !
Any help would be appreciated.
Interesting that it gives that output, considering how roles are indexed. Please note that roles are indexed based on the @everyone
role, for your owner role to be above your admin role it must have a higher position number. Upsettingly, I can't seem to find anything that describes this behavior, however testing does provide this behavior.
Setting Owner to 3, Admin to 2, and Mod to 1 should give your desired results.
... it is still really odd that Mod ends up above Owner with your current position values, but it is what it is I guess.
Seems that role create method and its data properties for position are indexed in a odd way and its indexed by 2 for a role to be higher than another.
code:
if(message.content.startsWith(prefix + "createrole")){
message.guild.roles.create({
data: {
name: "Owner",
color: "BLUE",
position: 5
}
})
.then(role => console.log(red(`Role created`)))
.catch(err => console.log(err))
message.guild.roles.create({
data: {
name: "Admin",
color: "BLUE",
position: 3
}
})
.then(role => console.log(red(`Role created`)))
.catch(err => console.log(err))
message.guild.roles.create({
data: {
name: "Mod",
color: "BLUE",
position: 1
}
})
.then(role => console.log(red(`Role created`)))
.catch(err => console.log(err))
}
Result:
This is still very confusing to me but it is what it is.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.