我已经制作了一个 Discord Node.JS 机器人一段时间了,我正在处理“取消禁止”命令,但我遇到的问题是两个问题,首先它尝试取消禁止成员,即使他们没有被禁止,其次是最大的,client.fetchUser(toUnban)无法解析诸如“.username”和“.avatarURL”之类的内容。我尝试制作一个单独的系统来收集这些数据(因为它有效)并且它只能在函数中使用它。不在它之外。client.fetchUser(toUnban) .then(user => console.log(user.username)) .then(user => usersname = user.username) .catch(console.error)console.log(usersname)会打印(例如)Clichefoox如果在此函数之外调用,它将不打印任何内容。如果在里面调用它会打印一些东西。问题是我正在尝试使其获得 avatarURL 和用户名。所以我不知道如何在一个 RichEmbed 中实现两者。完整代码:const Discord = require('discord.js')exports.run = (client, message, args) => { if (!message.member.hasPermission("BAN_MEMBERS") || !message.author == message.guild.owner) return message.channel.send("You don't have access to this command. :x:") if (!message.guild.me.hasPermission("ADMINISTRATOR")) return message.channel.send(`${message.guild.owner} did not give me permission to do this! If you are the owner, please run this command \`${client.config.PREFIX}fixserver\`!`) let toUnban = args[0] if (!toUnban) return message.channel.send("You did not give a User ID!") if (toUnban.includes("@")) { return message.channel.send("That is not a User ID!") } let reason = args.slice(1).join(" ") if (!reason) reason = "No reason." var Embed = new Discord.RichEmbed() .setColor('#ebe234') .setTimestamp() .setDescription(`**${client.fetchUser(toUnban).username}** has been unbanned from the server!`) .setFooter(`V${client.config.VERSION} | ${toUnban}`, client.user.displayAvatarURL) .setAuthor("Unbanned", client.fetchUser(toUnban).avatarURL) .addField("User", message.author.tag, true) .addField("Reason", reason, true) var cEmbed = new Discord.RichEmbed() .setColor('#2b2b2b') .setTimestamp() .setDescription(`**${client.fetchUser(toUnban).username}** has been unbanend.`) .setAuthor("Unbanned", client.fetchUser(toUnban).avatarURL) .addField("Reason", reason)预期的结果是它会根据Client#FetchUser理解用户名,它传递“User”类,所以我尝试将它称为普通的 User 类,但没有得到错误或输出,它只是空白。
2 回答
![?](http://img1.sycdn.imooc.com/54584d9f0001043b02200220-100-100.jpg)
catspeake
TA贡献1111条经验 获得超0个赞
.then(user => console.log(user.username))告诉代码接收用户,打印 user.username ,然后返回 console.log 的返回值,这是未定义的。
尝试
.then(user => {
console.log(user.username);
return user;
}
或者,更简洁
.then(user => console.log(user.username) || user)
添加回答
举报
0/150
提交
取消