CodecademyCommunity / codecademy-discord-bot

Custom moderation bot for the official Codecademy Community Discord server.
https://codecademycommunity.github.io/
MIT License
11 stars 1 forks source link

TypeError occuring in the Filter command #233

Closed mikejoh12 closed 2 years ago

mikejoh12 commented 2 years ago

Describe the bug

According to server logs it appears there is a TypeError occuring in the Filter command on incoming messages.

Error msg: /websocket/handlers/MESSAGE_CREATE.js:4:32) at WebSocketManager.handlePacket (/root/codecademy-discord-bot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:384:31) at WebSocketShard.onPacket (/root/codecademy-discord-bot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:444:22) at WebSocketShard.onMessage (/root/codecademy-discord-bot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:301:10) at WebSocket.onMessage (/root/codecademy-discord-bot/node_modules/ws/lib/event-target.js:132:16) TypeError: Cannot read property 'roles' of null at isHighRoller (/root/codecademy-discord-bot/commands/moderation/filter.js:58:17) at Object.execute (/root/codecademy-discord-bot/commands/moderation/filter.js:43:9) at Client. (/root/codecademy-discord-bot/app.js:199:35) at Client.emit (events.js:314:20) at MessageCreateAction.handle (/root/codecademy-discord-bot/node_modules/discord.js/src/client/actions/MessageCreate.js:31:14) at Object.module.exports [as MESSAGE_CREATE] (/root/codecademy-discord-bot/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32) at WebSocketManager.handlePacket (/root/codecademy-discord-bot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:384:31) at WebSocketShard.onPacket (/root/codecademy-discord-bot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:444:22) at WebSocketShard.onMessage (/root/codecademy-discord-bot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:301:10) at WebSocket.onMessage (/root/codecademy-discord-bot/node_modules/ws/lib/event-target.js:132:16)

It appears that some kind of message is getting through the messageHandler function and is passed to the filter command where it throws an error in the isHighRoller function due to no msg.member property. It appears the server is restarting due to the TypeError.

Expected behavior

No TypeError should occur.

To Reproduce

I have been unable to reproduce the error locally but suspecting that it could possibly be due to a webhook msg, DM or other non-standard msg. However, those are currently validated in the messageHandler function.

Additional context

Checking for the msg.member property in the messageHandler component is a potential improvement that could avoid the message to be passed to filter function where it throws the error.