无法读取未定义的属性“通道”

时间:2020-08-09 00:30:32

标签: javascript discord discord.js

所以我一直在尝试制作一个不和谐的机器人,当用户(被工作人员踢)被踢时,它将向日志通道发送嵌入内容,但会不断抛出错误

Cannot read property 'channels' of undefined

这是我的代码:

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>");
}

我尝试做

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

但是即使这样也行不通。我问过我的一些朋友,甚至他们都不知道,如果有人可以帮助我,我将非常感激!

(我还应该说我是编程新手)

1 个答案:

答案 0 :(得分:1)

我了解不多,但是我认为这是您应该这样做的方式。

更改以下内容

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

对此(如果您有Discord.js v12):

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

或这个(如果您有Discord.js v11):

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