繁体   English   中英

我的discord.js帮助命令无法正常工作

[英]My discord.js help command doesn't exactly work

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

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

我的第二个问题是,当邮件以嵌入方式发送时,它显示如下:

  • 命令
  • 描述
  • 用法
  • 未定义

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

我的代码:

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"
    }

当您使用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库:它是一个处理命令的框架,还处理错误,不完整的命令以及许多其他东西。 如果您想检查一下,可以在此处找到文档。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM