問題描述
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 初學者.
當我啟動命令時,在控制臺中我看到錯誤:
When i start the command, in console i see the error:
(節點:6312)UnhandledPromiseRejectionWarning:ReferenceError:消息沒有定義在 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
僅在消息事件本身中定義.因此,您可以簡單地將 message
對象作為參數傳遞給您的函數.
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
}
請記住,您必須在調用函數時添加附加參數.
Just remember that you'll have to add the additional parameter when you call the function.
message.channel.send(userInfo(userInfMent, message));
這篇關于Discord.js 錯誤 = “消息未定義"的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!