Discord.js: TypeError: Cannot read property 'roles' of null

Created on 15 Aug 2019  Â·  6Comments  Â·  Source: discordjs/discord.js

Hello, my bot is randomly crashing when I add new role to member, and new member (with role) is trying to use bot (you can use my bot only when you have special role on server), after script restart everything works perfectly.
its not even DM message, its channel message

discordclient.on('message', async message => {

    if (message.author.bot) { return; }

    if (message.channel.name == "copypaste") {
        if (message.content.includes("imgur.com")) {
            if (message.member.roles.find(r => r.name.includes("PASTER")) {

crashing on last line

(node:15948) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'roles' of null
    at Client.<anonymous> (/root/discordbot/index.js:38:23)
    at Client.emit (events.js:203:13)
    at MessageCreateHandler.handle (/root/discordbot/node_modules/discord.js/src/client/websocket/packets/handlers/MessageCreate.js:9:34)
    at WebSocketPacketManager.handle (/root/discordbot/node_modules/discord.js/src/client/websocket/packets/WebSocketPacketManager.js:105:65)
    at WebSocketConnection.onPacket (/root/discordbot/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:333:35)
    at WebSocketConnection.onMessage (/root/discordbot/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:296:17)
    at WebSocket.onMessage (/root/discordbot/node_modules/ws/lib/event-target.js:120:16)
    at WebSocket.emit (events.js:203:13)
    at Receiver.receiverOnMessage (/root/discordbot/node_modules/ws/lib/websocket.js:789:20)
    at Receiver.emit (events.js:203:13)
(node:15948) 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:15948) [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.

unverified bug

All 6 comments

Ok we'll try and work on a fix asap for easier contact add EXLPRO-DEV
TEAM#3644 on discord

On Thu, 15 Aug 2019, 7:39 pm SFx2018, notifications@github.com wrote:

Hello, my bot is randomly crashing when I add new role to member, and new
member (with role) is trying to use bot (you can use my bot only when you
have special role on server), after script restart everything works
perfectly.
its not even DM message, its channel message

discordclient.on('message', async message => {

if (message.author.bot) { return; }

if (message.channel.name == "copypaste") {
if (message.content.includes("imgur.com")) {
if (message.member.roles.find(r => r.name.includes("PASTER")) {

crashing on last line

(node:15948) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'roles' of null
at Client. (/root/discordbot/index.js:38:23)
at Client.emit (events.js:203:13)
at MessageCreateHandler.handle (/root/discordbot/node_modules/discord.js/src/client/websocket/packets/handlers/MessageCreate.js:9:34)
at WebSocketPacketManager.handle (/root/discordbot/node_modules/discord.js/src/client/websocket/packets/WebSocketPacketManager.js:105:65)
at WebSocketConnection.onPacket (/root/discordbot/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:333:35)
at WebSocketConnection.onMessage (/root/discordbot/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:296:17)
at WebSocket.onMessage (/root/discordbot/node_modules/ws/lib/event-target.js:120:16)
at WebSocket.emit (events.js:203:13)
at Receiver.receiverOnMessage (/root/discordbot/node_modules/ws/lib/websocket.js:789:20)
at Receiver.emit (events.js:203:13)
(node:15948) 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:15948) [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.

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/discordjs/discord.js/issues/3431?email_source=notifications&email_token=ALMYPCWFETW66ATPOUCYC7DQEWID7A5CNFSM4IMAJPHKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HFPNLQQ,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ALMYPCQZO4LJ6V3C2E57DVDQEWID7ANCNFSM4IMAJPHA
.

__The issue tracker is only for bug reports and enhancement suggestions. If you have a question, please ask it in the Discord server instead of opening an issue – you will get redirected there anyway.__

So is it all ok now?

On Thu, 15 Aug 2019, 7:49 pm SFx2018, notifications@github.com wrote:

Ok we'll try and work on a fix asap for easier contact add EXLPRO-DEV
TEAM#3644 on discord
… <#m_-7673439029364291595_>
On Thu, 15 Aug 2019, 7:39 pm SFx2018, @.*> wrote: Hello, my bot is
randomly crashing when I add new role to member, and new member (with role)
is trying to use bot (you can use my bot only when you have special role on
server), after script restart everything works perfectly. its not even DM
message, its channel message discordclient.on('message', async message => {
if (message.author.bot) { return; } if (message.channel.name ==
"copypaste") { if (message.content.includes("imgur.com")) { if
(message.member.roles.find(r => r.name.includes("PASTER")) { crashing on
last line (node:15948) UnhandledPromiseRejectionWarning: TypeError: Cannot
read property 'roles' of null at Client. (/root/discordbot/index.js:38:23)
at Client.emit (events.js:203:13) at MessageCreateHandler.handle
(/root/discordbot/node_modules/discord.js/src/client/websocket/packets/handlers/MessageCreate.js:9:34)
at WebSocketPacketManager.handle
(/root/discordbot/node_modules/discord.js/src/client/websocket/packets/WebSocketPacketManager.js:105:65)
at WebSocketConnection.onPacket
(/root/discordbot/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:333:35)
at WebSocketConnection.onMessage
(/root/discordbot/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:296:17)
at WebSocket.onMessage
(/root/discordbot/node_modules/ws/lib/event-target.js:120:16) at
WebSocket.emit (events.js:203:13) at Receiver.receiverOnMessage
(/root/discordbot/node_modules/ws/lib/websocket.js:789:20) at Receiver.emit
(events.js:203:13) (node:15948) 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:15948) [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. — You are receiving this because you are
subscribed to this thread. Reply to this email directly, view it on GitHub <

3431 https://github.com/discordjs/discord.js/issues/3431?email_source=notifications&email_token=ALMYPCWFETW66ATPOUCYC7DQEWID7A5CNFSM4IMAJPHKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HFPNLQQ>,

or mute the thread
https://github.com/notifications/unsubscribe-auth/ALMYPCQZO4LJ6V3C2E57DVDQEWID7ANCNFSM4IMAJPHA
.

ok, thank you, no rush, after script restart everything works fine

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/discordjs/discord.js/issues/3431?email_source=notifications&email_token=ALMYPCV6NFWTNGE2324T6TLQEWJLJA5CNFSM4IMAJPHKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4MQIWY#issuecomment-521733211,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ALMYPCQ5UX7CIRJLNUE6HXTQEWJLJANCNFSM4IMAJPHA
.

Was never broken in the first place.

everything works fine after script restart, but for example

my discordbot is working for 2-3 days, then I will add new role called "PASTER" for new member, and when he will paste imgur.com link to channel called #copypaste script randomly crash

(node:15948) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'roles' of null
    at Client.<anonymous> (/root/discordbot/index.js:38:23)
    at Client.emit (events.js:203:13)
    at MessageCreateHandler.handle (/root/discordbot/node_modules/discord.js/src/client/websocket/packets/handlers/MessageCreate.js:9:34)
    at WebSocketPacketManager.handle (/root/discordbot/node_modules/discord.js/src/client/websocket/packets/WebSocketPacketManager.js:105:65)
    at WebSocketConnection.onPacket (/root/discordbot/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:333:35)
    at WebSocketConnection.onMessage (/root/discordbot/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:296:17)
    at WebSocket.onMessage (/root/discordbot/node_modules/ws/lib/event-target.js:120:16)
    at WebSocket.emit (events.js:203:13)
    at Receiver.receiverOnMessage (/root/discordbot/node_modules/ws/lib/websocket.js:789:20)
    at Receiver.emit (events.js:203:13)
(node:15948) 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:15948) [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.

its happening like 1 time per 10 days, otherwise everything works fine, I have no idea why my script is randomly crashing with this error

Ok good to hear! Contact us on discord or email in the future if you
need anything.

On Thu, 15 Aug 2019, 8:01 pm tipakA, notifications@github.com wrote:

Was never broken in the first place.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/discordjs/discord.js/issues/3431?email_source=notifications&email_token=ALMYPCT2M4PXFDZMXYKFHW3QEWKXFA5CNFSM4IMAJPHKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4MRI4Q#issuecomment-521737330,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ALMYPCRQEEN4NWG2RAVYCO3QEWKXFANCNFSM4IMAJPHA
.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Blumlaut picture Blumlaut  Â·  3Comments

Brawaru picture Brawaru  Â·  3Comments

DatMayo picture DatMayo  Â·  3Comments

tiritto picture tiritto  Â·  3Comments

smchase picture smchase  Â·  3Comments