(Discord.JS) - Reaction Role error: "Cannot Read Property "roles" of Undefined"

Asked

Viewed 153 times

0

I am trying to make a "Reaction Role" command so that members can receive certain positions. Currently, I use this code:

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

    let servidor = client.guilds.cache.get("774274642520965180")
    let membro = servidor.members.cache.get(dados.d.user_id);

    let cafet = servidor.roles.cache.get("<@&780176147681378335>"),
        inkei = servidor.roles.cache.get("<@&780175676380414002>"),
        mokuzai = servidor.roles.cache.get("<@&780175676380414002>");
    if(dados.t === "MESSAGE_REACTION_ADD") {
        if (dados.d.emoji.id === "774669881996083220") {
            if (membro.roles.cache.has(cafet)) return
            membro.roles.add(cafet);
        } else if (dados.d.emoji.id === "775031385542885406") {
            if (membro.roles.cache.has(inkei)) return
            membro.roles.add(inkei);
        } else if (dados.d.emoji.id === "774665913559023738") {
            if (membro.roles.cache.has(mokuzai)) return
            membro.roles.add(mokuzai);
        }
    }
})

However, this error following is returning to me on the console:

(node:3048) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'roles' of undefined
    at Client.<anonymous> (C:\Users\Leaofy\Desktop\Woah!\index.js:29:24)
    at Client.emit (events.js:315:20)
    at WebSocketShard.onMessage (C:\Users\Leaofy\Desktop\Woah!\node_modules\discord.js\src\client\websocket\WebSocketShard.js:295:27)
    at WebSocket.onMessage (C:\Users\Leaofy\Desktop\Woah!\node_modules\ws\lib\event-target.js:132:16)
    at WebSocket.emit (events.js:315:20)
    at Receiver.receiverOnMessage (C:\Users\Leaofy\Desktop\Woah!\node_modules\ws\lib\websocket.js:825:20)
    at Receiver.emit (events.js:315:20)
    at Receiver.dataMessage (C:\Users\Leaofy\Desktop\Woah!\node_modules\ws\lib\receiver.js:437:14)
    at Receiver.getData (C:\Users\Leaofy\Desktop\Woah!\node_modules\ws\lib\receiver.js:367:17)
    at Receiver.startLoop (C:\Users\Leaofy\Desktop\Woah!\node_modules\ws\lib\receiver.js:143:22)
(node:3048) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:3048) [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.

If anyone can help me, I’ll be immensely grateful!!!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.