Cannot read property 'channel' of undefined

how can I fix this?

client.on(“ready”, async message => {
console.log(I am online, my name is ${client.user.username});
message.channel.send(I am online, my name is ${client.user.username});

});

this is my error message

(node:12208) UnhandledPromiseRejectionWarning: TypeError: Cannot read property ‘channel’ of undefined

please help me

since you are in the “ready” event, there is no message to refer to. try using this instead:

client.on(“ready”, async message => {
console.log(I am online, my name is ${client.user.username});
client.channels.get("CHANNELIDFORLOGS").send(I am online, my name is ${client.user.username});
});
1 Like

now i get this error

UnhandledPromiseRejectionWarning: TypeError: Cannot read property ‘send’ of undefined

did you change “CHANNELIDFORLOGS” to the id of your logging channel?

i dont have a logging channel

oh. it works now. thank you so much for the help

2 Likes

no problem! glad to help :slight_smile:

1 Like