因此,我正在使用我在源代码浏览器中找到的这段代码与我的机器人在Discord上实施其fortnite命令。运行后,它显示:
(node:11358) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'toLowerCase' of undefined
at new User (/rbd/pnpm-volume/872a58d7-c703-412a-a641-c8df3e275a0a/node_modules/.registry.npmjs.org/fortnite/4.1.1/node_modules/fortnite/src/User.js:13:73)
at /rbd/pnpm-volume/872a58d7-c703-412a-a641-c8df3e275a0a/node_modules/.registry.npmjs.org/fortnite/4.1.1/node_modules/fortnite/src/Client.js:61:24
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:189:7)
(node:11358) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:11358) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
const Discord = require("discord.js");
const Client = require('fortnite');
const fortnite = new Client(`config.TRN_API_KEY`);
module.exports.run = async(bot, message, args) => {
let username = args[0];
let platform = args[1];
if (!username) return message.channel.send("Please, provide a users nickname!(Fortnite)")
if (!platform) return message.channel.send("Did you provide a platform ? Proper usage : ** ? fortnite < username > < platform > ** ")
let data = fortnite.user(username, platform).then(data => {
let stats = data.stats;
let lifetime = stats.lifetime;
let score = lifetime[6]['Score'];
let mplayed = lifetime[7]['Matches Played'];
let wins = lifetime[8]['Wins'];
let winper = lifetime[9]['Win%'];
let kills = lifetime[10]['Kills'];
let kd = lifetime[11]['K/d'];
let embed = new Discord.RichEmbed()
.setTitle("Lifetime Stats")
.setAuthor(data.username)
.setColor("RANDOM")
.addField("Wins", wins, true)
.addField("Kills", kills, true)
.addField("Score", score, true)
.addField("Matches Played", mplayed, true)
.addField("Win%", winper, true)
.addField("K/D", kd, true)
.setTimestamp()
.setFooter("Requested By " + message.author.tag, message.author.avatarURL);
message.channel.send(embed);
}).catch((err) => {
message.channel.send('User not found!');
console.error(err);
});
}
module.exports.help = {
name: "fortnite"
}
我真的只是想找出问题所在。我的直觉说这是user.js的问题,但我可能错了。我所知道的是,当我想要它时它不起作用。这是一个命令脚本,我从Source Code Explorer(源代码资源管理器)获得,只是想亲自尝试一下,但始终遇到.toLowerCase
错误。如您所见,此脚本中甚至都没有定义它。我该怎么办?
这是user.js脚本的代码:
const Mode = require('./Mode');
const Stat = require('./Stat');
/** Class representing a full user */
class User {
/**
* @param {Object} data All of the data resolved from the API
*/
constructor(data) {
this.id = data.accountId;
this.username = data.epicUserHandle;
this.platform = data.platformNameLong;
this.url = `https://fortnitetracker.com/profile/${data.platformName.toLowerCase()}/${this.username}`;
this.stats = {};
for (const mode in data.stats) {
// Replace the playlist id with its name for the keys
this.stats[modes[mode]] = new Mode(data.stats[mode]);
}
// TODO: Make lifetime single objects and not an array
// Will be updated in a newer version
this.stats.lifetime = data.lifeTimeStats.map(stat => new Stat(stat));
}
}
const modes = {
p2: 'solo',
p10: 'duo',
p9: 'squad',
curr_p2: 'current_solo',
curr_p10: 'current_duo',
curr_p9: 'current_squad'
};
module.exports = User;
答案 0 :(得分:0)
因此,这是我的问题的更新和修复。他们最终给我发送了一封电子邮件,说他们已经解决了一些问题,并重新生成了令牌并重试。代码完美运行。感谢大家的帮助,我非常感谢。
答案 1 :(得分:0)
我不确定 .toLowerCase 在哪里,但根据事实判断,如果你写了 .toLowerCase,我会告诉你这是错误的。 toLowerCase 是一个函数,而不是一个属性。每当你做 .toLowerCase() <-- 看到括号了吗?这就是定义任何函数的方式。但是您使用的是类,所以我想您也知道这一点