【问题标题】:Invalid left-hand side in assignment | Discord.js赋值中的左侧无效 |不和谐.js
【发布时间】:2021-01-10 04:41:19
【问题描述】:

我只是想测试我的机器人是否工作,我很确定我做的一切都正确,但似乎有问题。每次我运行我的 ping 命令时,它都会向我抛出一个错误。

错误:

(node:9304) UnhandledPromiseRejectionWarning: ReferenceError: Invalid left-hand side in assignment
    at Object.run (C:\Users\Familia\OneDrive\Documents\Other Stuff\Visual Studio code\blade\commands\ping.js:10:38)
    at Client.<anonymous> (C:\Users\Familia\OneDrive\Documents\Other Stuff\Visual Studio code\blade\bot.js:55:42)

我的 Ping.js 代码:

const Discord = require('discord.js')

module.exports = {
    name: "ping",
    description: "test command",

    async run (client, message, args) {


        const ping = new Discord.MessageEmbed()
        .setDescription(`????\`${Date.now() - message.createdTimestamp}\`ms`);


        message.channel.send(ping);
    }
}

这是 bot.js:55:42 的参考:

client.on("message", async message => {

    if(message.content.startsWith(prefix)) {
        const args = message.content.slice(prefix.length).trim().split(/ +/);

        const command = args.shift().toLowerCase();

        if(!client.commands.has(command)) return;

        try {
            client.commands.get(command).run(client, message, args); // This line
        } catch (error){
            console.error(error);
        }
    }
}) 

如果这似乎是一个愚蠢的问题,我很抱歉,我很抱歉!

【问题讨论】:

    标签: node.js discord discord.js


    【解决方案1】:

    我刚刚添加了以下代码:

    client.on("message", async message => {
    
        if(message.author.bot) return;
        if(message.channel.type === 'dm') return;
    }
    

    由于某种原因,它起作用了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-26
      • 2018-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-16
      • 2016-11-24
      • 1970-01-01
      相关资源
      最近更新 更多