如何解决TypeError:channel.send不是函数不建议使用?
我正在尝试构建一个不和谐的机器人,但是我需要向特定的频道发送消息。我已经给了它100次尝试,但不断得到:
TypeError: bot.channels.fetch(...).send is not a function.
我在所有阅读的地方都看到“ use channel.send()”,但找不到解决我问题的实际方法。 channel.send()是否已弃用?这是错误引发错误的行:
bot.channels.fetch(id).send(message);
我知道channel.get()已被描述,当使用.fetch(id)时,我得到了channel对象,但是它不允许我发送消息。谢谢您的帮助,因为我已经花了几天的时间在此上。 谢谢。
完整的代码块:
var reportEmbed = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle('New Report')
.setAuthor(msg.author.tag)
.setDescription(reportMessage)
.setTimestamp();
console.log(bot.channels.fetch('my channel id'));
bot.channels.fetch('my channel id').then(channel => {
channel.send(reportEmbed);
});
登录控制台后,我得到了正确的频道对象。
解决方法
正如我在文档中看到的那样,fetch()方法返回一个promise。 (Link)
因此,要获取频道,您需要使用当前代码:
bot.channels.fetch("id").then(channel => {
channel.send(message);
});
,
尝试使用:
bot.channels.cache.get(id).send(message)
相反
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。