discord.js V12“过滤器"未定义

2022-01-10 00:00:00 javascript discord.js

所以我将我的机器人更新为 discord.js V12 命令;whois 出现错误(node:553) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'filter' of undefined

So I was updating my bot to discord.js V12 the command ;whois is bringing up an error (node:553) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'filter' of undefined

Node.js 是 Discord.js 的当前版本,我知道它是否与代码有关

Node.js is the current version for Discord.js I do know if it has to do with the code

const { MessageEmbed } = require("discord.js");
const { stripIndents } = require("common-tags");
const { getMember, formatDate } = require("../../functions.js");

module.exports = {
  config:{
    name: "whois",
    aliases: ["who", "user", "info"],
   category: "info",
    description: "Returns user information",
    usage: "[username | id | mention]"
  },
    run: (client, message, args) => {
        const member = getMember(message, args.join(" "));

        // Member variables
        const joined = formatDate(member.joinedAt);
        const roles = member.roles
            .filter(r => r.id !== message.guild.id)
            .map(r => r).join(", ") || 'none';

如果我删除 .filter &.map 使用 .createdAT 弹出另一个错误

If I remove .filter & .map another error pops up with .createdAT

  // User variables
        const created = formatDate(member.user.createdAt);

        const embed = new MessageEmbed()
            .setFooter(member.displayName, member.user.displayAvatarURL({ dynamic:true }))
            .setThumbnail(member.user.displayAvatarURL({ dynamic:true }))
            .setColor(member.displayHexColor === '#000000' ? '#ffffff' : member.displayHexColor)
            .setAuthor(`${member.displayName} | WHOIS`, member.user.displayAvatarURL)

            .addField('Member information:', stripIndents`** Display name:** ${member.displayName}
            ** Joined at:** ${joined}
            ** Roles:** ${roles}`, true)

            .addField('User information:', stripIndents`** ID:** ${member.user.id}
            ** Username**: ${member.user.username}
            ** Tag**: ${member.user.tag}
            ** Created at**: ${created}`, true)

            .setTimestamp()

        if (member.user.presence.game) 
            embed.addField('Currently playing', stripIndents`** Name:** ${member.user.presence.activity.name}`);

        message.channel.send(embed);
    }
}

现在这就是整个 whois 代码,我不知道还有什么需要更新的.

Now thats is the whole whois code I don't know what else needs to get updated.

推荐答案

要在 v12 中访问 GuildMemberroles 集合,您需要使用 cache.

To access the GuildMember's roles collection in v12 you need to use cache.

const roles = member.roles.cache.filter(r => r.id !== message.guild.id).map(r => r).join(", ") || 'none';

相关文章