简体   繁体   English

JavaScript(discord.js)TypeError:无法读取未定义的属性“startsWith”

[英]JavaScript(discord.js) TypeError: Cannot read property 'startsWith' of undefined

When i was compiling the source code of my Discord bot, i get this:当我编译我的 Discord 机器人的源代码时,我得到了这个:

TypeError: Cannot read property 'startsWith' of undefined

This is the code:这是代码:

const { PREFIX } = require("../config.json");

module.exports = (client, aliases, callBack) => {

if (typeof aliases === "string")

{
    aliases = [aliases];
}

client.on("message", message => {
    const { CONTENT } = message;

    aliases.forEach(alias => {
        const COMMAND = ${PREFIX}${alias};

        if (CONTENT.startsWith(`${COMMAND}`) || CONTENT === COMMAND)
        {
            console.log(Asuna is running the command "${COMMAND}"...);

            callBack(message);
        }
    });
});

} }

I think you're not getting the actual message content from the message's object (Therefore it is undefined ).You could try to just set the message content to a constant.我认为您没有从消息的 object 中获取实际的消息内容(因此它是undefined )。您可以尝试将消息内容设置为常量。

const msg = message.content;

Then just use msg in your code.然后只需在您的代码中使用msg即可。

if (msg.startsWith(`${COMMAND}`) || msg === COMMAND)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Discord.JS UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性“startsWith” - Discord.JS UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'startsWith' of undefined 无法读取 Discord.js 上未定义的属性“startsWith” - Cannot read property 'startsWith' of undefined on Discord.js 类型错误:无法读取未定义 Discord.js javascript 的属性“添加” - TypeError: Cannot read property 'add' of undefined Discord.js javascript JavaScript TypeError:无法读取未定义的属性'startsWith'-Discord Bot - JavaScript TypeError: Cannot read property 'startsWith' of undefined - discord bot 类型错误:无法读取未定义的属性 'has' // Discord.js - TypeError: Cannot read property 'has' of undefined // Discord.js 遇到 TypeError:无法读取 Discord.JS 中未定义的属性“0” - Encountering TypeError: Cannot read property '0' of undefined in Discord.JS TypeError:无法读取未定义的属性“数据”| discord.js - TypeError: Cannot read property 'data' of undefined | discord.js 类型错误:无法读取未定义的属性“角色”|| Discord.js - TypeError: Cannot read property 'roles' of undefined || Discord.js (Discord.js)TypeError:无法读取未定义的属性“添加” - (Discord.js) TypeError: Cannot read property 'add' of undefined Discord.js:类型错误:无法读取未定义的属性“删除” - Discord.js : TypeError: Cannot read property 'remove' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM