K
K
Kirill2020-09-26 16:07:02
Node.js
Kirill, 2020-09-26 16:07:02

How to fix this Discord.js error?

const Discord = require('discord.js');
const strftime = require('strftime');
module.exports = {
  name: 'profile',
  description: 'Get the profile of the tagged user, or your own profile.',
  execute(message) {
    const member = message.mentions.users.first(); // Тут ошибка
    let argsUser
    if (!member) argsUser = message.author
    else argsUser = member.user

    let statuses = {
      online: 'Онлайн',
      idle: 'Не активен',
      dnd: 'Не беспокоить',
      offline: 'Оффлайн'
    }
    let game
    if(!argsUser.presence.game) game = `**${statuses[argsUser.presence.status]}**`
    else if (argsUser.presence.game.type == 0) game = `Играет в **${argsUser.presence.game.name}**`
    else if (argsUser.presence.game.type == 1) game = `Стримит [**${argsUser.presence.game.name}**](${argsUser.presence.game.url})`
    else if (argsUser.presence.game.type == 2) game = `Слушает **${argsUser.presence.game.name}**`
    else if (argsUser.presence.game.type == 3) game = `Смотрит **${argsUser.presence.game.name}**`

    let day = 1000 * 60 * 60 * 24
    let date1 = new Date(message.createdTimestamp)
    let date2 = new Date(argsUser.createdTimestamp)
    let date3 = new Date(message.guild.member(argsUser).joinedTimestamp)
    let diff1 = Math.round(Math.abs((date1.getTime() - date2.getTime()) / day)) // С момента регистрации
    let diff2 = Math.round(Math.abs((date1.getTime() - date3.getTime()) / day)) // С момента вступления на сервер

    let pembed = new Discord.MessageEmbed()
      .setTitle('Профиль участника ' + argsUser.username)
      .addField('Статус:', game)
      .addField('ID:', argsUser.id)
      .addField('Дата регистрации:', `${strftime('%d.%m.%Y', new Date(argsUser.createdTimestamp))}\n(${diff1} дн. назад)`, true)
      .addField('Дата вступления:', `${strftime('%d.%m.%Y', new Date(message.guild.member(argsUser).joinedTimestamp))}\n(${diff2} дн. назад)`, true)
      .addField('Роли:', message.guild.member(argsUser).roles.cache.filter(r => r.id !== message.guild.id).map(r => r).join(", ") || 'Нет')
      .setColor(message.guild.member(argsUser).displayHexColor)
      .setTimestamp()
      .setThumbnail(argsUser.avatarURL())
    message.channel.send(pembed)
  },
};


TypeError: Cannot read property 'member' of undefined
at Object.execute (C:\Users\Kirill\Documents\Discord Bots\crazy-bot\commands\profile.js:6:30)
at Client. (C:\Users\Kirill\Documents\Discord bots\crazy-bot\index.js:141:11)
at Client.emit (events.js:315:20)
at MessageCreateAction.handle (C:\Users\Kirill\ Documents\Discord bots\crazy-bot\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (C:\Users\Kirill\Documents\Discord bots\crazy-bot\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (C:\Users\Kirill\Documents\Discord bots\crazy-bot\node_modules \discord.js\src\client\websocket\WebSocketManager.js:384:31)
at WebSocketShard.onPacket (C:\Users\Kirill\Documents\Discord bots\crazy-bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
at WebSocketShard.onMessage (C:\Users \Kirill\Documents\Discord bots\crazy-bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
at WebSocket.onMessage (C:\Users\Kirill\Documents\Discord bots\crazy -bot\node_modules\ws\lib\event-target.js:125:16)
at WebSocket.emit (events.js:315:20)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2020-01-03
@BigTooth

I can advise you to change it. It should work, because I myself often use something like this code. If my answer satisfied you, please mark it with a tick.

execute(message, member) {
    let любое_другое_имя_переменной = message.guild.member(message.mentions.users.first());
//и дальше ваш код
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question