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

discord.js V12 #39;filter#39; undefined(discord.js V12“过滤器未定义)

本文介绍了discord.js V12“过滤器"未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我将我的机器人更新为 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';

这篇关于discord.js V12“过滤器"未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:discord.js V12“过滤器"未定义

基础教程推荐