命令未运行且没有错误消息

Posted

技术标签:

【中文标题】命令未运行且没有错误消息【英文标题】:Commands not running with no error message 【发布时间】:2021-07-19 10:46:41 【问题描述】:

我试图为我的 discord bot 运行多个命令,bot 由于某种原因一个单一的命令没有运行。这是我的 main.js 文件中的代码:

client.on('message', message => 
    if(!message.content.startsWith(prefix) || message.author.bot) return
    const args = message.content.slice(prefix.length).trim().split(' ');
    const command = args.shift().toLowerCase();

    if(command === 'petfeed') 
        client.commands.get('petfeed').execute(message, args, Discord);
    else if(command === 'petwater') 
        client.commands.get('petwater').execute(message, args, Discord); 
        //this is one of the commands that runs perfectly fine. The command has virtually identical code to the petfeed command in its file but with a few small changes
);

这是我要运行的命令:

const db = require('quick.db')

module.exports = 
    name: 'petfeed',
    description: 'feeds your pet',
    execute: async (message, args, Discord) => 
        let user = message.author
        let fullness = await db.fetch(`fullness_$user.id`)
        let food = await db.fetch(`food_$user.id`)

        if(fullness === null) fullness = 0;
        if(food === null) food = 0;
        
        if(fullness < 3 && food >= 1) 
            db.add(`fullness_$user.id`, 1)
            db.subtract(`food_$user.id`, 1)
        
    

我有其他非常相似的命令运行得非常好,但是当我尝试运行它时,这个命令什么也没做,而且它不会返回任何错误。

【问题讨论】:

能否在命令文件中添加一个console.log(),以便查看它是否运行。 @mmoomocow 我把一个作为执行后的第一行,但仍然没有 您保存文件并重新启动机器人了吗?因为如果模块已经加载,console.log() 应该已经工作了。 @Radnerus 是的,我做到了,两次只是为了确保 你能举例说明如何运行另一个命令 【参考方案1】:

不知何故将 main.js 文件和命令文件中的名称更改为 petfood 解决了这个问题。如果我将它改回 petfeed,它会再次停止工作。

【讨论】:

以上是关于命令未运行且没有错误消息的主要内容,如果未能解决你的问题,请参考以下文章

node dist/server.js 退出且没有错误消息

Django 静态文件未加载且没有错误迹象

Espresso UI 测试已取消且没有错误消息

php/mysqli 查询未执行某些查询且没有错误

AS3 中的“TypeError:错误 #1010:术语未定义且没有属性”

MSBuild命令行错误 - 未安装Silverlight 4 SDK