DEV Community

Discussion on: Creating An Announcement Discord Bot

Collapse
 
dejf15 profile image
Dejf15 • Edited

I need help, every time I start my bot everything runs smoothly until i write the command !announce test, after writing the command, I always have this error in the console:

C:\Program Files\nodejs\node.exe .\index.js
Ready for action!
index.js:8
Uncaught TypeError: Cannot read property 'roles' of null
index.js:12
Debugger attached.
Waiting for the debugger to disconnect...
c:\Users\radad\node_modules\discord.js\index.js:12
if (!message.member.roles.cache.has(config["announcer-role"]) || !message.content.startsWith("!") || message.author.bot) return;
^

TypeError: Cannot read property 'roles' of null
at Client. (c:\Users\radad\node_modules\discord.js\index.js:12:23)
at Client.emit (events.js:315:20)
at MessageCreateAction.handle (c:\Users\radad\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
at Object.module.exports as MESSAGE_CREATE
at WebSocketManager.handlePacket (c:\Users\radad\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:31)
at WebSocketShard.onPacket (c:\Users\radad\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
at WebSocketShard.onMessage (c:\Users\radad\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
at WebSocket.onMessage (c:\Users\radad\node_modules\ws\lib\event-target.js:132:16)
at WebSocket.emit (events.js:315:20)
at Receiver.receiverOnMessage (c:\Users\radad\node_modules\ws\lib\websocket.js:825:20)

Collapse
 
shadowtime2000 profile image
shadowtime2000

Turning on the bot myself also causes this error now. I do not know why it is being caused, I will look at updating the tutorial once I have solved it.