[英]Discord.js: message.guild.channels.forEach is not a function
[英]Discord.js: member.guild.channels.find is not a function
所以我现在正在尝试为我的不和谐机器人发送一条欢迎信息,但不知何故我有一个非常奇怪的问题,显然 members.guild.channels.find() 不是一个函数。
client.on('guildMemberAdd', member =>{
const channel = member.guild.channels.find(channel => channel.name === "welcome");
if(!channel) return;
const welcomeEmbed = new Discord.MessageEmbed()
.setColor(pink)
.setAuthor('IdealBot', 'https://hypixel.net/attachments/ideal-png.1417277/', 'https://hypixel.net/threads/ideal-ideal-%E2%9D%96-level-52-%E2%9D%96-sweaty-skyblock-guild-%E2%9D%96-top-10-sb-guild-%E2%9D%96-splashes-%E2%9D%96-events-%E2%9D%96-recruiting.2500755/')
.setTitle('Welcome!')
.setDescription(`${member} just joined the discord! Make sure to read #rules!`)
.setThumbnail(message.user.avatarURL)
.setFooter('Note: The maximum amount of answers is 9.')
.setTimestamp();
channel.send(welcomeEmbed);
});
然而,当我尝试运行它时,出现错误:TypeError:无法读取未定义的属性“查找”
我很确定我以前用过这个,有人知道这个错误可能来自哪里吗?
你输入了member.guild.channel.find
。 将其更改为member.guild.channels.cache.find
,因为它不久前已更改。 有关更多信息,请参阅文档。
嗯,我猜您尝试访问的属性不存在。 看起来必须使用channels
而不是channel
,见下文:
const channel = member.guild.channels.find(channel => channel.name === "welcome");
另请参阅每个 X 用户的欢迎消息示例,该属性也可以通过.channels
访问
我也有这个问题,要解决它试试 member.guild.channels.find()
此外,除非您有括号,否则 message.user.avatarURL 将不起作用 - 即 message.user.avatarURL() 因为它是一个函数。
让我知道这个是否奏效
const channel = member.guild.channels.cache.find(channel => channel.name === 'welcome');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.