简体   繁体   中英

discord.js Linkfilter TypeError: Cannot read property 'roles' of null

I have an error on my linkfilter system. Something with the roles is not working.

https://sourceb.in/pwvz5xjucp

This is the error I get:

(node:12236) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'roles' of null
    at Client.<anonymous> (C:\Users\eFhii\Desktop\Venetic eSports\development_discord\index.js:134:24)
    at Client.emit (events.js:327:22)
    at MessageCreateAction.handle (C:\Users\eFhii\Desktop\Venetic eSports\development_discord\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
    at Object.module.exports [as MESSAGE_CREATE] (C:\Users\eFhii\Desktop\Venetic eSports\development_discord\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
    at WebSocketManager.handlePacket (C:\Users\eFhii\Desktop\Venetic eSports\development_discord\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:31)
    at WebSocketShard.onPacket (C:\Users\eFhii\Desktop\Venetic eSports\development_discord\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
    at WebSocketShard.onMessage (C:\Users\eFhii\Desktop\Venetic eSports\development_discord\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
    at WebSocket.onMessage (C:\Users\eFhii\Desktop\Venetic eSports\development_discord\node_modules\ws\lib\event-target.js:132:16)
    at WebSocket.emit (events.js:315:20)
    at Receiver.receiverOnMessage (C:\Users\eFhii\Desktop\Venetic eSports\development_discord\node_modules\ws\lib\websocket.js:825:20)
    at Receiver.emit (events.js:315:20)
    at Receiver.dataMessage (C:\Users\eFhii\Desktop\Venetic eSports\development_discord\node_modules\ws\lib\receiver.js:437:14)
    at Receiver.getData (C:\Users\eFhii\Desktop\Venetic eSports\development_discord\node_modules\ws\lib\receiver.js:367:17)
    at Receiver.startLoop (C:\Users\eFhii\Desktop\Venetic eSports\development_discord\node_modules\ws\lib\receiver.js:143:22)
    at Receiver._write (C:\Users\eFhii\Desktop\Venetic eSports\development_discord\node_modules\ws\lib\receiver.js:78:10)
    at doWrite (_stream_writable.js:403:12)

As message.member returns GuildMember in this case there is no member.
What does that mean? that means someone messaged bot in private chat (DMs)
To solve this just ignore messages if it is not in a server:
if(.message;guild) return; so your code will be something like this:\

//Linkfilter
bot.on("message", async message => {
    if(!message.guild) return;
    const mongo = require('./mongo')
    const warnSchema = require('./models/warn-schema')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM