DiscordJS Bot Error

In my Discord.JS bot I get this error when I run

It happens when I type anything with the prefix (-)

C:\Users\Sybri\Documents\gggggg>node index.js
[11:02:49] INFO Loaded core giveaways.
[11:02:49] INFO Loaded core moderatie.
[11:02:49] INFO Loaded core tickets.
[11:02:49] INFO Loaded core utilities.
[11:02:49] INFO Loaded addon join.js.
[11:02:49] INFO Loaded addon rank.js.
[11:02:49] INFO Loaded addon tag.js.
[11:02:53] (node:10052) UnhandledPromiseRejectionWarning: TypeError: Cannot read property ‘id’ of undefined
at C:\Users\Sybri\Documents\gggggg\events\message.js:154:84
at Map.find (C:\Users\Sybri\Documents\gggggg\node_modules@discordjs\collection\dist\index.js:161:17)
at C:\Users\Sybri\Documents\gggggg\events\message.js:154:60
at Array.forEach ()
at Client.client.checkPermissions (C:\Users\Sybri\Documents\gggggg\events\message.js:154:13)
at module.exports (C:\Users\Sybri\Documents\gggggg\events\message.js:199:40)
at Client.emit (events.js:326:22)
at MessageCreateAction.handle (C:\Users\Sybri\Documents\gggggg\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (C:\Users\Sybri\Documents\gggggg\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (C:\Users\Sybri\Documents\gggggg\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:31)
(Use node --trace-warnings ... to show where the warning was created)
[11:02:53] (node:10052) 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)
[11:02:53] (node:10052) [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.

Share the code that’s causing this error.

1 Like

Seems like your trying to apply .id to a promise something in your file message.js @ line 154. Show us that line, and hopefully we can help.

1 Like

Try adding an await before acccessing the id property and make sure the function using it is async. You can also try the (promise).then coding pattern as an alternative

I prefer promise.then tbh