Discord.js error = quot;message is not definedquot;(Discord.js 错误 = “消息未定义)
问题描述
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 错误 = “消息未定义"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Discord.js 错误 = “消息未定义"
基础教程推荐
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
