Estoy codificando un bot de discordia y estoy tratando de obtener el contenido de las incrustaciones a través del comando que el usuario responde al mensaje y usa un prefijo. Cuando intento ejecutar el comando, dice que fetchedMsg.embeds[0] no existe. ¿Hay algo mal con mi código?
if (msg.reference) { const fetchedMsg = await msg.channel.messages.fetch(msg.reference.messageID) console.log(fetchedMsg) console.log(fetchedMsg.embeds[0]) } El error está en la línea console.log(fetchedMsg.embeds[0]) , y mirando el registro del código antes de que incluya embeds: [ [MessageEmbed] ], .
El error dice TypeError: Cannot read properties of undefined (reading '0') , y cuando elimino el [0] , no está definido. Todo esto está en un module.exports.run , si eso ayuda.
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 fetchedMsgPuede obtener MessageEmbed() igual que el Message normal usando:
const messages = args[0] if(!messages) return message.reply("Provide an ID for message.") if(isNaN(messages)) return message.reply("Message ID should be number, not a letter") message.channel.messages.fetch(`${messages}`) .then(msg => { console.log(msg.content) || console.log(msg.embeds) })Puede encontrar más información aquí sobre cómo obtener un mensaje