繁体   English   中英

类型错误:无法读取未定义的属性“反应”

[英]TypeError: Cannot read property 'react' of undefined

我收到以下错误,需要一点帮助!

Error TypeError: Cannot read property 'react' of undefined

我想编写一个代码来添加对特定消息的反应,包括公会、频道和消息 ID!

这是我的代码:

let servidor = bot.guilds.cache.get("guildid");

let canal = servidor.channels.cache.get("channelid");

let mensagem = canal.messages.cache.get("messageid");

mensagem.react("765350841330171904");

mensagem.react("765350842005454858");

您的错误意味着消息 ID 不正确,或者更常见的是消息未缓存。 这可能是因为它是在您上次重新启动机器人之前发送的。 幸运的是,您可以使用MessageManager.fetch()直接从 Discord 的 API(或缓存,如果可用)获取消息。

此方法确实返回一个承诺,因此请确保您的函数是async或者您使用.then()来处理它。

const servidor = bot.guilds.cache.get("guildid");
const canal = servidor.channels.cache.get("channelid");
const mensagem = await canal.messages.fetch("messageid"); // fetch the message

mensagem.react("765350841330171904");
mensagem.react("765350842005454858");

暂无
暂无

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

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