問(wèn)題描述
const Discord = require('discord.js');
exports.run = async (bot, message, args) => {
let userInfMent = message.guild.member(message.mentions.users.first() || message.guild.members.get(args[0]))
message.channel.send(userInfo(userInfMent));
}
function userInfo(user) {
const Discord = require('discord.js');
let userInfMent = message.guild.member(message.mentions.users.first() || message.guild.members.get(args[0]))
var userCreated = userInfMent.createdAt.toString().split(' ');
var lastMsg = userInfMent.lastMessage.createdAt.toString().split(' ')
const userInfoEmbed = new Discord.RichEmbed()
.addField('Никнейм: ', userInfMent.username)
.addField('Тег: ', userInfMent.tag)
.addField('ID: ', userInfMent.id)
.addField('Аккаунт был создан: ', userCreated[1] + ', ' + userCreated[2] + ', ' + userCreated[3])
.addField('Последнее сообщение: ', userInfMent.lastMessage + ' в ' + lastMsg[1] + ', ' + lastMsg[2] + ', ' + lastMsg[3] + ', ' + lastMsg[4])
.addField('Статус: ', userInfMent.presence.status)
.setColor('RANDOM')
.setThumbnail(userInfMent.avatarURL);
return userInfoEmbed
}
嗨.我是 Node.js 初學(xué)者.
當(dāng)我啟動(dòng)命令時(shí),在控制臺(tái)中我看到錯(cuò)誤:
When i start the command, in console i see the error:
(節(jié)點(diǎn):6312)UnhandledPromiseRejectionWarning:ReferenceError:消息沒(méi)有定義在 userInfo (C:UsersderisDesktopПроектыNode.jsdiscord.jsJSBot-mastercommandsuserinfo.js:10:23)在 Object.exports.run (C:UsersderisDesktopПроектыNode.jsdiscord.jsJSBot-mastercommandsuserinfo.js:5:26)
(node:6312) UnhandledPromiseRejectionWarning: ReferenceError: message is not defined at userInfo (C:UsersderisDesktopПроектыNode.jsdiscord.jsJSBot-mastercommandsuserinfo.js:10:23) at Object.exports.run (C:UsersderisDesktopПроектыNode.jsdiscord.jsJSBot-mastercommandsuserinfo.js:5:26)
推薦答案
message
僅在消息事件本身中定義.因此,您可以簡(jiǎn)單地將 message
對(duì)象作為參數(shù)傳遞給您的函數(shù).
message
is only defined in the message event itself. So you can simply pass the message
object as a parameter into your function.
// new function
function userInfo(user, message) {
//code here
}
請(qǐng)記住,您必須在調(diào)用函數(shù)時(shí)添加附加參數(shù).
Just remember that you'll have to add the additional parameter when you call the function.
message.channel.send(userInfo(userInfMent, message));
這篇關(guān)于Discord.js 錯(cuò)誤 = “消息未定義"的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!