TypeError:无法读取discord.js中未定义的属性“ members”

时间:2019-08-18 20:17:49

标签: javascript node.js bots discord

我正在尝试创建一个Javascript Discord机器人,该机器人在单击特定评论的表情符号时会给用户一个角色(反应角色),但是我收到以下代码错误

代码:

client.on('raw', async data => {
    if(data.t !== "MESSAGE_REACTION_ADD" && data.t !== "MESSAGE_REACTION_REMOVE") return
    if(data.d.message_id != "612715176122384414") return

    let canal = client.guilds.get("612380691522387985")
    let cara = canal.members.get(data.d.user_id)

    let novato = canal.roles.get('612715206400802837')

    if(data.t === "MESSAGE_REACTION_ADD"){
        if(data.d.emoji.name === "✅"){ 
            if(cara.roles.has(novato)) return 
            cara.addRole(novato) 
        }
    }

    if(data.t === "MESSAGE_REACTION_REMOVE"){
        if(data.d.emoji.name === "✅"){
            if(cara.roles.has(novato)) return
            cara.removeRole(novato)
        }
    }

})

错误:

(node:1324) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'members' of undefined
    at Client.client.on (C:\Users\Ori\Documents\Discord\TesterBot\bot.js:133:22)
    at Client.emit (events.js:203:15)
    at WebSocketConnection.onPacket (C:\Users\Ori\Documents\Discord\TesterBot\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:317:17)
    at WebSocketConnection.onMessage (C:\Users\Ori\Documents\Discord\TesterBot\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:296:17)
    at WebSocket.onMessage (C:\Users\Ori\Documents\Discord\TesterBot\node_modules\ws\lib\event-target.js:120:16)
    at WebSocket.emit (events.js:198:13)
    at Receiver.receiverOnMessage (C:\Users\Ori\Documents\Discord\TesterBot\node_modules\ws\lib\websocket.js:789:20)
    at Receiver.emit (events.js:198:13)
    at Receiver.dataMessage (C:\Users\Ori\Documents\Discord\TesterBot\node_modules\ws\lib\receiver.js:422:14)
    at Receiver.getData (C:\Users\Ori\Documents\Discord\TesterBot\node_modules\ws\lib\receiver.js:352:17)
(node:1324) UnhandledPromiseRejectionWarning: Unhandled promise rejection.

此错误是由内部异步函数引发的 没有阻碍或拒绝诺言 无法使用.catch()处理。 (拒绝ID:1) (节点:1324)[DEP0018] DeprecationWarning:已弃用未处理的承诺拒绝。将来,未处理的承诺拒绝将以非零值终止Node.js进程 退出代码。

0 个答案:

没有答案