我无法使.startsWith正常工作,并且只能在特定文件上使用

问题描述 投票:0回答:1

[每当执行.startsWith时,都会给我一个错误。具体来说就是这样:属性'startsWith'在'string'类型上不存在。如果我在index.js上尝试使用.startsWith,而在index.ts上则不可行。这是我所拥有的:

    client.on("message", function (msg) {
if (msg.author.bot) {
    return;
}
if (!msg.content.startsWith(ConfigFile.config.prefix)) {
    return;
}
msg.channel.send(msg.author.username + " this better work.");

});

任何想法如何解决此问题?

typescript discord.js
1个回答
0
投票

也许字符串原型发生了某些事情。试试这个技巧:

String.prototype.startsWith.call(msg.content, ConfigFile.config.prefix)
© www.soinside.com 2019 - 2024. All rights reserved.