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

时间:2020-05-16 18:37:44

标签: javascript discord.js

因此,我正在将我的机器人更新为discord.js V12,该命令出现错误。 (节点:553)UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性“ filter”

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

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

  // 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代码,我不知道还有什么需要更新。

2 个答案:

答案 0 :(得分:2)

要访问v12中的GuildMember的{​​{1}}集合,您需要使用roles

cache

答案 1 :(得分:0)

Discord.js指南:

v12引入了管理器的概念,您将不再能够在诸如Client#users之类的数据结构上直接使用诸如Collection#get之类的收集方法。现在,在尝试使用收集方法之前,您将必须直接在管理器上请求缓存。直接在管理器上调用的任何方法都将调用API,例如GuildMemberManager#fetch和MessageManager#delete

  • OLD:client.users.get('123456789012345678');
  • 新功能:client.users.cache.get('123456789012345678');
  • OLD:channel.messages.get('123456789012345678');
  • 新功能:channel.messages.cache.get('123456789012345678');
  • OLD:guild.members.get('123456789012345678');
  • 新功能:guild.members.cache.get('123456789012345678');

有关更多信息,请参考Updating from v11 to v12