我一直收到这个错误
<块引用>TypeError: 无法读取未定义的属性 'channel'
let channel = message.guild.channel.cache.find('830754717108797450')
这是我的代码:
const MinecraftCommand = require('../../contracts/MinecraftCommand')
const Discord = require('discord.js-light');
const { Message } = require('discord.js-light');
const ms = require('pretty-ms');
const client = require ('discord.js-light')
class GuildMemberReportCommand extends MinecraftCommand {
onCommand(username, message) {
let args = this.getArgs(message)
let reason = args[1];
let guild = message.guild.cache.get('')
let channel = message.guild.channel.cache.find('830754717108797450')
let reporteduser = args[0];
let embed = new Discord.MessageEmbed()
.setTitle("Guild Member Report!")
.addField("Reason", reason)
.addField("Reported By", username)
.addField("Reported User", reporteduser)
.setColor("#f49542")
if (!reason) return this.send('Report reason needs to be specified!', username);
if (!username) return this.send ('Reported member was not speified!', username);
this.send(`${username}, $args[0] has been reported!, Please be patient when staff checks your report!`)
channel.send(embed).then(i => i.react("⏳"))
}
}
module.exports = GuildMemberReportCommand```
答案 0 :(得分:0)
你必须检查这个变量:
let guild = message.guild.cache.get('')
只需在此语句后加上 console.log('guild', guild)
。可能您可能需要捕获正确的字段才能在公会中获取通道对象。
答案 1 :(得分:0)
.find()
方法接受一个函数。对于您的情况,您可以使用箭头功能。例如:..cache.find(ch=>ch.id==='yourid')
其中 ch
将是您的情况下的频道对象。