从msg.reference.messageid中获取嵌入的嵌入吗?
我正在编码一个Discord机器人,并且正在尝试通过命令用户回复消息并使用前缀来获取嵌入的内容。当我尝试运行命令时,它说fetchedmsg.embeds [0]
不是一事。我的代码有什么问题吗?
if (msg.reference) {
const fetchedMsg = await msg.channel.messages.fetch(msg.reference.messageID)
console.log(fetchedMsg)
console.log(fetchedMsg.embeds[0])
}
该错误在行console.log(fetchedmsg.embeds [0])
上,并在包含embeds之前从代码中查看日志:[[[messageMeatbed]],
。
错误读取typeError:无法读取未定义的属性(读取'0')
,当我删除[0]
时,它是未定义的。这整个过程都在module.exports.run
中,如果有帮助。
module.exports.run = async (client, msg, args) => {
const { MessageActionRow, MessageButton, MessageEmbed } = require('discord.js');
if (args.length === 5) {
if (msg.reference) {
const fetchedMsg = await msg.channel.messages.fetch(await msg.reference.messageID)
console.log(fetchedMsg)
console.log(fetchedMsg.embeds[0])
}
//do things with fetchedMsg
I am coding a discord bot, and I am trying to get the content of embeds through the command user replying to the message and using a prefix. When I try running the command, it says that fetchedMsg.embeds[0]
isn't a thing. Is there anything wrong with my code?
if (msg.reference) {
const fetchedMsg = await msg.channel.messages.fetch(msg.reference.messageID)
console.log(fetchedMsg)
console.log(fetchedMsg.embeds[0])
}
The error is on the line console.log(fetchedMsg.embeds[0])
, and looking at the log from the code before it includes embeds: [ [MessageEmbed] ],
.
The error reads TypeError: Cannot read properties of undefined (reading '0')
, and when I remove the [0]
, it's undefined. This whole thing is in a module.exports.run
, if that helps.
module.exports.run = async (client, msg, args) => {
const { MessageActionRow, MessageButton, MessageEmbed } = require('discord.js');
if (args.length === 5) {
if (msg.reference) {
const fetchedMsg = await msg.channel.messages.fetch(await msg.reference.messageID)
console.log(fetchedMsg)
console.log(fetchedMsg.embeds[0])
}
//do things with fetchedMsg
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以获取
MessageEmbed()
与normal消息
使用:您可以在这里找到有关获取消息的更多信息
You can get the
MessageEmbed()
same as normalMessage
using:You can find more here about fetching a message