【问题标题】:My discord.js help command doesn't exactly work我的 discord.js 帮助命令不能正常工作
【发布时间】:2019-04-13 12:04:13
【问题描述】:

首先,我的帮助命令确实有效,但不是以我希望的方式工作。

我的第一个问题是命令是在单独的消息中发送的,当你有很多命令时这有点烦人。

我的第二个问题是,当消息在嵌入中发送时,它会显示如下:

  • 命令
  • 说明
  • 用法
  • 未定义

我尝试了多种方法来摆脱“未定义”。

我的代码:

const fs = require("fs");
const Discord = require("discord.js");

module.exports.run = async(bot, message, args, con) => {
   fs.readdir("./commands/", (err, files) => {
     if(err) console.error(err);

    let jsfiles = files.filter(f => f.split(".").pop() === "js");
    if(jsfiles.length <= 0) {
        console.log("No commands to load!");
        return;
    }

    var namelist = "";
    var desclist = "";
    var usage = "";

    let result = jsfiles((f, i) => {
        let props = require(`./${f}`);
        namelist = props.help.name;
        desclist = props.help.description;
        usage = props.help.usage;

        // send help text
        let helpembed = new Discord.RichEmbed()
        .setTitle("Commands")
        .setFooter("Please report any bugs to Vati#1662")
        .setColor("RANDOM")
        .addField(`**${namelist}** \n${desclist} \n${usage}`)  
        message.author.sendEmbed(helpembed);
    });

   })
  }
    module.exports.help = {
    name: "help",
    description: "shows all commands",
    usage: "help"
    }

【问题讨论】:

    标签: node.js discord discord.js


    【解决方案1】:

    当您使用RichEmbed.addField() 时,它至少需要两个参数:字段的标题及其值。

    .addField(`**${namelist}** \n${desclist} \n${usage}`) // this has only the title argument
    

    尝试将三个“部分”放在三个不同的字段中。

    .addField("Name:", namelist, true) // the 'true' means that they're inline fileds
    .addField("Usage:", usage, true) // they will try to fit on the same line
    .addField("Description:", desclist) // if there's no third argument, the default is 'false'
    

    命令以不同的消息发送,因为您正在为每个命令运行整个代码,而不仅仅是为每个命令添加字段。如果你不想花时间在所有这些东西上,你可以使用discord.js-commando 库:它是一个处理命令并处理错误、不完整命令和许多其他东西的框架。如果你想查看它,你可以找到文档here。

    【讨论】:

      猜你喜欢
      • 2020-11-14
      • 1970-01-01
      • 2018-07-28
      • 2020-11-22
      • 2021-12-20
      • 2021-01-12
      • 2021-04-25
      • 1970-01-01
      • 2020-11-15
      相关资源
      最近更新 更多