TypeError: Cannot read property 'toLowerCase'
TypeError: Cannot read property 'toLowerCase'
所以我正在使用我在源代码资源管理器上找到的这段代码来实现他们的 fortnite 命令与我的机器人在 discord 上。在 运行 上面,它说:
(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;
所以这是对我的问题的更新和修复。他们最后给我发了一封电子邮件,说他们已经解决了一些问题并重新生成令牌并重试。代码完美运行。谢谢大家的帮助,我真的很感激。
我不确定 .toLowerCase 在哪里,但根据事实判断 属性 如果你写的 .toLowerCase 是错误的,我会告诉你。 toLowerCase 是一个函数,而不是 属性。每当你执行 .toLowerCase() <-- 看到括号?这就是定义任何函数的方式。但是您使用的是 class,所以我假设您也知道
所以我正在使用我在源代码资源管理器上找到的这段代码来实现他们的 fortnite 命令与我的机器人在 discord 上。在 运行 上面,它说:
(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;
所以这是对我的问题的更新和修复。他们最后给我发了一封电子邮件,说他们已经解决了一些问题并重新生成令牌并重试。代码完美运行。谢谢大家的帮助,我真的很感激。
我不确定 .toLowerCase 在哪里,但根据事实判断 属性 如果你写的 .toLowerCase 是错误的,我会告诉你。 toLowerCase 是一个函数,而不是 属性。每当你执行 .toLowerCase() <-- 看到括号?这就是定义任何函数的方式。但是您使用的是 class,所以我假设您也知道