尝试使用 msg.mentions.users.first 执行 dm 命令,但它不起作用

问题描述

    if(msg.content.startsWith("&%walcome")){
        const mentionid = bot.users.cache.get(`${msg.mentions.users.first().id}`)
            const up = new discord.MessageEmbed()
            .setColor('#C8CAF9')
            .setTitle('Sup')
            .setThumbnail(`${msg.mentions.users.first().displayAvatarURL()}`)
            .setDescription(`Sup **${msg.mentions.user.first().tag}**,be welcome to mfpA Official discord Community. If you joined withouht kNowing wth is this server,I will explain: this is the official server of the series with the same new,that is available on youtube (https://www.youtube.com/channel/UCWZRrkidNF5Se8fkgGzoxgg)`)
            .addFields(
                {name: 'Fun in server',value: 'That is right,dear new member,you can actually have fun in this channel! We have some custom emojis,events,chat (sometimes is dead but eh-). But!,first of all,do not forget to go to #verify (823564914605686844) to get access to the server'},{name: 'Specific Announcements',value: 'You can receive specific announcements (Faded Pics,Betro Ideas and Dani Sounds) if you are interested in the whole production of the series'},{name: 'If you need help,just dm a staff member',value: 'Thats right,if you need help,you can contact one of the Staff Team member,they will reply when available'}
            )
            .setFooter(`Sent by ${msg.author.tag},bot made by dani bear#3606`,`${msg.author.displayAvatarURL()}`)
               mentionid.send(up)
            }
})

所以,这段代码不起作用,我不知道为什么。错误Cannot read property 'first' of undefined,但我已经使用了它并且它有效-

如果你能帮忙我将不胜感激!

解决方法

您在 .setDescription('Sup **${msg.mentions.user.first().tag...)}' 中有一个拼写错误。它是 msg.mentions.users.first()(在 'users' 中漏掉了一个 's')。此外,如果您要一次又一次地使用提到的 User 对象,请将 then 存储在一个变量中,然后访问该对象的属性。