discord.js V12 #39;filter#39; undefined(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 中访问 GuildMember
的 roles
集合,您需要使用 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“过滤器"未定义
基础教程推荐
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- 直接将值设置为滑块 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01