我希望管理员,mod,...在其姓名前都具有其角色的前缀,并且我已经写了一些起作用的东西,但是如果此人有多个带前缀的角色并且一个被删除,则删除的过多或前缀太少,如果您没有按照将角色添加到它们的相同顺序删除它们:
const PREFIX = {
"331525375622381578": "[CC]",
"368443021500612608": "[Mod]",
"476419648565411840": "[StA]",
"432961003588943882": "[Sub]",
"525439226507034626": "[VIP]",
"420592943376629760": "[U]"
}
client.on('guildMemberUpdate', (mold, mnew) => {
var guild = mnew.guild
if (mold.roles.array().length < mnew.roles.array().length) {
var role = mnew.roles.find(r => mold.roles.find(rold => rold.id == r.id) == null)
if (role.id in PREFIX) {
mnew.setNickname(`${PREFIX[role.id]} ${mnew.displayName}`)
}
}
else if (mold.roles.array().length > mnew.roles.array().length) {
var role = mold.roles.find(r => mnew.roles.find(rold => rold.id == r.id) == null)
if (role.id in PREFIX) {
mnew.setNickname(mnew.displayName.substr(PREFIX[role.id].length + 1))
}
}
})