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

时间:2022-11-20
本文介绍了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 禁用“交互失败" 下一篇:如何修复:“TypeError:无法读取未定义的属性‘标签’"discord.js 中的错误

相关文章

最新文章