从msg.reference.messageid中获取嵌入的嵌入吗?

发布于 2025-02-07 12:25:14 字数 1009 浏览 1 评论 0原文

我正在编码一个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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

水中月 2025-02-14 12:25:14

您可以获取MessageEmbed()与normal 消息使用:

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)
        })

您可以在这里找到有关获取消息的更多信息

You can get the MessageEmbed() same as normal Message using:

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)
        })

You can find more here about fetching a message

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文