无法添加和删除角色

时间:2019-03-10 07:51:35

标签: javascript discord discord.js

我正在开发一个不和谐的bot,但遇到一个让我震惊的问题。
我有一个带角色的练级系统,它可以很好地与“成员”角色配合使用,但随后开始出现问题,这是我的代码:

var member = msg.guild.roles.find(role => role.name === 'member')
var Lurker = msg.guild.roles.find(role => role.name === 'Lurker')
var Shy = msg.guild.roles.find(role => role.name === 'Shy')
if (msg.member.roles.find(role => role.name === 'member')) {

 if (profile.xp + 35 > 230) {
   let card = await jimp.read('https://i.imgur.com/mZD99TV.png')
   await dl.AddLevel(msg.author.id, 1)
   await dl.SetXp(msg.author.id, 0)

   jimp.read(msg.author.displayAvatarURL).then(avatar => {
     avatar.resize(180, 180)
     mask.resize(180, 180)
     avatar.mask(mask)
     card.print(font64, 470, 100, `Level UP!`)
     card.composite(avatar, 40, 50).write('LVLUP.png')
     client.channels.get('552975320131567638').send(``, {
       files: ["LVLUP.png"]
     })

     console.log('Image sent!')
   })

   msg.channel.send("Congratulations " + `<@` + msg.author.id + `>` + ` You've just advanced  level ${profile.level + 1}`)
 }
 if (profile.level + 1 == 6) {
   msg.member.addRole(Lurker)
 }
}

if (msg.member.roles.find(role => role.name === 'Lurker')) {

 if (profile.xp + 35 > 467) {
   let card = await jimp.read('https://i.imgur.com/mZD99TV.png')
   await dl.AddLevel(msg.author.id, 1)
   await dl.SetXp(msg.author.id, 0)

   jimp.read(msg.author.displayAvatarURL).then(avatar => {
     avatar.resize(180, 180)
     mask.resize(180, 180)
     avatar.mask(mask)
     card.print(font64, 470, 100, `Level UP!`)
     card.composite(avatar, 40, 50).write('LVLUP.png')
     client.channels.get('552975320131567638').send(``, {
       files: ["LVLUP.png"]
     })

     console.log('Image sent!')
   })

   msg.channel.send("Congratulations " + `<@` + msg.author.id + `>` + ` You've just advanced  level ${profile.level + 1}`)
 }

 if (profile.level + 1 == 11) {
   msg.member.addRole(Shy);
 }
}

第一个if (msg.member.roles.find(role => role.name === 'member'))可以很好地工作,但是if (msg.member.roles.find(role => role.name === 'Lurker'))却不能。
该漫游器未将角色添加到该成员,而是发送了2条“ Level up”消息,而不是1条消息。我不知道出了什么问题,日志中什么也没有。

0 个答案:

没有答案