मैं इसे ठीक करना चाहता हूं और मैं चाहता हूं कि जब उपयोगकर्ता 1 उपयोगकर्ता 2 को एक भूमिका नाम zzz दें और उपयोगकर्ता 1 में सीसीसी भूमिका न हो, तो उपयोगकर्ता 2 से भूमिका ज़ज़ को हटा दें उपयोगकर्ता 1 में सीसीसी भूमिका नहीं है

(node:4544) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'map' of undefined
    at pluck (C:\Dev\DiscordTickets-master\auto.js:5:18)
    at hasRole (C:\Dev\DiscordTickets-master\auto.js:9:8)
    at newMember.guild.fetchAuditLogs.then.logs (C:\Dev\DiscordTickets-master\auto.js:21:8)
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:4544) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:4544) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.


function pluck(array) {
    return array.map(function(item){ return item["name"]})
}

function hasRole(mem, role){
    if(pluck(mem.roles).includes(role)){
        return true;
    } else {
        return false;
    }
}

client.on('guildMemberUpdate', (oldMember, newMember) => {
    var cca = newMember.guild.channels.find(c => c.name === 'bots');
    newMember.guild.fetchAuditLogs().then(logs => {
        if(oldMember.roles.size < newMember.roles.size) {
            var role25 = newMember.guild.roles.find(r => r.name === 'zzz');
      var ex = logs.entries.first().executor;
      if(!hasRole(ex, "ccc"))return newMember.removeRole( role25 );  
        }
    })
});
-2
Ana Mido King 27 मार्च 2020, 14:08

1 उत्तर

सबसे बढ़िया उत्तर