Discord.js 错误 = “消息未定义"

Discord.js error = quot;message is not definedquot;(Discord.js 错误 = “消息未定义)
本文介绍了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 v12: How do I await for messages in a DM channel?(discord.js v12:我如何等待 DM 频道中的消息?)
how to make my bot mention the person who gave that bot command(如何让我的机器人提及发出该机器人命令的人)
How to fix Must use import to load ES Module discord.js(如何修复必须使用导入来加载 ES 模块 discord.js)
How to list all members from a specific server?(如何列出来自特定服务器的所有成员?)
Discord bot: Fix ‘FFMPEG not found’(Discord bot:修复“找不到 FFMPEG)
Welcome message when joining discord Server using discord.js(使用 discord.js 加入 discord 服务器时的欢迎消息)