每当我运行此命令时,都会出现以下错误:TypeError: Cannot read property 'user' of undefined
我认为错误在这里:let member = message.mentions.members.first()
但是为什么呢?
这是我的userinfo命令:
const Discord = require('discord.js');
module.exports = {
name: 'profile',
description: 'Get the profile of the tagged user, or your own profile.',
execute(message, args) {
let member = message.mentions.members.first() // any (why?)
const msapr = new Discord.MessageEmbed() // Профиль автора сообщения
.setColor ('0x0099ff')
.setTitle ('Профиль участника ' + message.author.username)
.addFields(
{ name: 'Ник:', value: `${message.author}` },
{ name: 'ID:', value: message.author.id }
)
.setThumbnail(message.author.avatarURL())
const mmupr = new Discord.MessageEmbed() // Профиль упомянутого пользователя
.setColor ('0x0099ff')
.setTitle ('Профиль участника ' + member.user.username)
.addFields(
{ name: 'Ник:', value: `${member}` },
{ name: 'ID:', value: member.user.id }
)
.setFooter (message.author.username, message.author.avatarURL())
.setThumbnail(member.user.avatarURL())
if (!message.mentions.users.size) {
return message.channel.send(msapr);
}
message.channel.send(mmupr)
},
};
错误:
TypeError: Cannot read property 'user' of undefined
at Object.execute (C:\Users\Кирилл\Documents\Дискорд боты\crazy-bot\commands\profile.js:17:45)
at Client.<anonymous> (C:\Users\Кирилл\Documents\Дискорд боты\crazy-bot\index.js:175:11)
at Client.emit (events.js:315:20)
at MessageCreateAction.handle (C:\Users\Кирилл\Documents\Дискорд боты\crazy-bot\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (C:\Users\Кирилл\Documents\Дискорд боты\crazy-bot\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (C:\Users\Кирилл\Documents\Дискорд боты\crazy-bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:31)
at WebSocketShard.onPacket (C:\Users\Кирилл\Documents\Дискорд боты\crazy-bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
at WebSocketShard.onMessage (C:\Users\Кирилл\Documents\Дискорд боты\crazy-bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
at WebSocket.onMessage (C:\Users\Кирилл\Documents\Дискорд боты\crazy-bot\node_modules\ws\lib\event-target.js:125:16)
at WebSocket.emit (events.js:315:20)
答案 0 :(得分:0)
您正在尝试获取username对象的GuildMember属性。但是它不存在。如果要访问User,则必须通过username对象。更改
readValue(...)
到
.setTitle ('Профиль участника', user.username)
答案 1 :(得分:0)
通过将用户初始化重命名为成员来更新用户初始化,然后选择openssl s_client -connect 3.135.190.131:50000 -cert ../client/client_certificate1.pem -key ../client/private_key.pem -CAfile ca_certificate.pem
或member.displayName
而不是member.user.username
,因为您的用户不是真实用户,而是成员。
参见GuildMember