【发布时间】:2021-06-15 00:48:48
【问题描述】:
我正在发出船舶命令,错误消息有效,但运输无效。我总是收到这个错误:Type Error: Cannot read property "username" of undefined。有人可以帮我解决吗?
这是我的代码:
const { DiscordAPIError } = require("discord.js");
const Discord = require('discord.js');
const client = new Discord.Client();
module.exports = {
name: 'ship',
description: "Ship two users!",
execute(message, args) {
const user = message.mentions.members.first();
const user2 = message.mentions.members.first(+1) ;
const images = [(1-100) code is different, put every number there]
const result = Math.floor(Math.random() * images.length);
const error = new Discord.MessageEmbed()
.setColor("#000000")
.setTitle("Ship")
.setDescription("There was an error: Check if you mentioned a user other than you!")
.setFooter(message.author.username)
.setTimestamp()
;
if(!user) return message.reply(error);
if(!user2) user2 = message.author.username;
if(user.id === message.author.id) return message.reply(error);
const embed = new Discord.MessageEmbed()
.setColor("#2A333E")
.setTitle("Ship")
.setDescription(user2.user.username + " + " + user.user.username + " =")
.addField(images[result] + "%" , "Is this good or not so good?")
.setFooter(message.author.username)
.setTimestamp()
;
message.channel.send(embed)
}}
【问题讨论】:
-
你能提供完整的堆栈跟踪吗?这将帮助我们确定我们需要关注哪条线
-
我已经看过了,是哪一行。它在 embed const 描述中,所以第 28 行。
标签: node.js discord discord.js bots