简体   繁体   English

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

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

I'm getting the following error and would like a little help!我收到以下错误,需要一点帮助!

Error TypeError: Cannot read property 'react' of undefined

I wanted to make a code that would add reactions to a certain message, including the guild, channel, and the message id!我想编写一个代码来添加对特定消息的反应,包括公会、频道和消息 ID!

Here my Code:这是我的代码:

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");

Your error means that the message ID is incorrect or, more commonly, that the message is not cached.您的错误意味着消息 ID 不正确,或者更常见的是消息未缓存。 This might've happened because it was sent before the last time you restarted your bot.这可能是因为它是在您上次重新启动机器人之前发送的。 Luckily, you can use MessageManager.fetch() which will get the message directly from Discord's API (or the cache if it's available).幸运的是,您可以使用MessageManager.fetch()直接从 Discord 的 API(或缓存,如果可用)获取消息。

This method does return a promise, so make sure your function is async or you use a .then() to handle it.此方法确实返回一个承诺,因此请确保您的函数是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