繁体   English   中英

channel.send 不是 function

[英]channel.send is not a function

我正在尝试为我的服务器发出一个欢迎命令,除了发送消息的机器人之外,我的一切都失败了。 当我尝试使用发送 function 发送消息时,它在控制台中说它不存在。 它不是 function。我真的不确定如何处理它,因为我在任何地方都找不到任何东西。

client.on('guildMemberAdd', member => {
  const channel1 = member.guild.channels.cache.find(channel => channel.name === "welcome");
  if (!channel1) return;

  channel1.send(`Welcome to the server, ${member} \n Thank you for joining!`);
})

您的.find()方法似乎返回CategoryChannel而不是TextChannel

CategoryChannel没有.send()方法,因此会出现错误。 您可以使您的.find()更具体以仅查找文本通道以避免此问题:

member.guild.channels.cache.find(channel => channel.type === 'text' && channel.name === "welcome");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM