frenchee1607
frenchee1607

Reputation: 13

Cannot read property 'channels' of undefined

So i have been trying to make a discord bot, when a user gets kicked (by a staff member) it will send a embed to a log channel but it keeps throwing errors

Cannot read property 'channels' of undefined

here is my code:

let embed = new Discord.MessageEmbed()
.setColor("RANDOM")
.setAuthor(message.author.tag,message.author.avatarURL())
.setFooter("Made by frenchee1607")
.addField("Moderation:", "kick")
.addField("Mutee:", member.user.username)
.addField("Moderator:", message.author.username)
.addField("Reason:", reason)
.addField("Date:", message.createdAt.toLocaleString())
let Channel = client.channels.find(channel => channel.name == "mods-chat-logger");        
if (Channel) {
    Channel.send(message)
} else {
    message.channel.send("Error sending embed to <#735829837306003456>");
}

I have tried doing

client.channels.cache.get("735829837306003456")

but even this wont work. I have asked some of my friend and even they dont know, if anyone can help I would be very grateful!

(I should also say that i am new to programming)

Upvotes: 0

Views: 1905

Answers (1)

TYPICAL NINJA
TYPICAL NINJA

Reputation: 150

I don't know much, but I think this is how you should do it.

Change the following

let Channel = client.channels.find(channel => channel.name == "mods-chat-logger");

to this (if you have Discord.js v12):

let Channel = message.client.channels.cache.find(channel => channel.name == "mods-chat-logger");

or this (if you have Discord.js v11):

let Channel = message.client.channels.find("name", "mods-chat-logger");

Upvotes: 1

Related Questions