首页 > 解决方案 > discord.js反应TypeError:无法读取未定义的属性'get'

问题描述

所以我试图从嵌入中收集反应,但我仍然收到这个错误:

      var peopleReacted = embedsend.reactions.get(party).users.array();
                                              ^

TypeError: Cannot read property 'get' of undefined
    at Timeout._onTimeout

这是我的代码:

message.channel.send(`${boost} **GIVEAWAY** ${boost}`, embed).then(sentEmbed => {
  sentEmbed.react(party)});
      
    setTimeout(function() {

      var random = 0;
      var winners = [];
      var inList = false;

      var peopleReacted = embedsend.reactions.get(party).users.array();

我也一直在尝试使用 sentEmbed.reactions.getorcache.get但后来我得到了sentEmbed is not definied

标签: discord.js

解决方案


其中一个错误是 in embedsend.reactions.get(party).users.array();,因为(假设你在 d.js 版本 12 中),你必须改为使用.cache,所以让它embedsend.reactions.cache.get(party).users.array();

另外,var embedsend = embed;不是消息,它是一个嵌入对象。相反,使用var embedsend = message.channel.send('${boost} **GIVEAWAY** ${boost}', embed);,然后它将设置为您发送的实际消息,而不是嵌入。


推荐阅读