命令处理程序显示不正确

时间:2020-05-31 05:18:33

标签: discord discord.js

我尝试添加命令处理程序,但是命令文件显示的值不正确,例如,机器人的ping显示为NaN,正常运行时间/用户/服务器均显示为零。该命令运行良好,直到我将其移动到自己的命令文件中为止。我不确定是什么问题,因为控制台中没有错误发生。请帮忙,下面是我index.js和一个命令文件的代码

关于问题出在哪里,我的最佳猜测是: module.exports = { 名称:bot, 说明:displays bot information., 执行(消息,参数){ //码 }

https://pastebin.com/hJ4nessW

1 个答案:

答案 0 :(得分:0)

您的library(data.table) rbindlist(df_list) 文件看起来有些行,而没有使用Discord.js的Embed class ...
在第一部分

bot.js

不是必需的,因为它是在index.js中定义的,因此应在index.js中使用

const Discord = require(`discord.js`);
const bot = new Discord.Client(); // <- here

和bot.js

    switch (args[0]) {

        case `ping`:
            bot.commands.get(`ping`).execute(message, args, bot /* use it */ );
            break;

        case `bot`:
            bot.commands.get(`bot`).execute(message, args, bot /* use it */ );
            break;

    }

我建议避免使用spaghetti code,因为它看起来更糟并且花费大量时间...我做了更短,更少的行和工作的代码版本-> https://pastebin.com/sRNacWYt