嵌入动态帮助命令的内容

时间:2020-06-01 13:03:08

标签: discord discord.js

因此,我使用不一致的文档编写了动态帮助命令。但是要使其醒目,我想将其嵌入并显示在用户DM中。 这是一个小片段-

execute(client, message, args) {
        const data = [];
        const { commands } = message.client;

        if (!args.length) {
            data.push('Here\'s a list of all my commands:'); //push on data var to append the info you want 
            data.push(commands.map(command => command.name).join('\n'));
            data.push(`\nYou can send \`${prefix}help [command name]\` to get info on a specific command!`);

            return message.author.send(data, { split: true })
                .then(() => {
                    if (message.channel.type === 'dm') return;
                    message.reply('I\'ve sent you a DM with all my commands!');
                })
                .catch(error => {
                    console.error(`Could not send help DM to ${message.author.tag}.\n`, error);
                    message.reply('it seems like I can\'t DM you! Do you have DMs disabled?');
                });
        }

反正我可以在嵌入中使用data.push吗?

3 个答案:

答案 0 :(得分:1)

您是说要嵌入并显示所有命令名称?

反正我可以在嵌入中使用data.push

不确定您的确切意思,但是据我了解,不,嵌入具有字段,文件,标题等属性,尽管您可以设置这些属性,而不用使用当前数据数组方法。

这可能是您想要的:

execute(client, message, args) {
  const data = [];
  const { commands } = message.client;
  if (!args.length) {
    //you'll need refrence to this somehow, like const {MessageEmbed} = require("discord.js")    
    const embed = new MessageEmbed()
      .setTitle("Here's a list of all my commands:");
      .setDescription(commands.map(cmd => cmd.name).join("\n"));
      .setFooter(`You can send \`${prefix}help [command name]\` to get info on a specific command!`);

    return message.author.send(data, { split: true })
      .then(() => {
        if (message.channel.type === 'dm') return;
        message.reply('I\'ve sent you a DM with all my commands!');
      })
      .catch(error => {
        console.error(`Could not send help DM to ${message.author.tag}.\n`, error);
        message.reply('it seems like I can\'t DM you! Do you have DMs disabled?');
      });
  }
}

答案 1 :(得分:1)

我曾经遇到过同样的问题,但是我已经解决了。

if (!args.length) {
const title = 'Here\'s a list of all my commands:';
const description = data.push(commands.map(command => command.name).join(', '));
const footer = `You can send ${prefix}help [command name] to get info on a specific command!`;
    const helpEmbed = new Discord.MessageEmbed()
    .setColor('RANDOM')
    .setAuthor(message.author.tag, message.author.displayAvatarURL({ dynamic: true }))
    .setTitle(title)
    .setDescription(data)
    .setTimestamp()
    .setFooter(footer);
return message.author.send(helpEmbed)
   .then(() => {
       if (message.channel.type === 'dm') return;
       message.reply('I\'ve sent you a DM with all my commands!');
   });

尝试一下。应该可以。

答案 2 :(得分:0)

const embed = new Discord.MessageEmbed()
    .setTitle("Command List :")
    .setColor("GREEN")
    .setDescription(data.join(" "));

如果您认为数据长度超过1024个字符,请尝试执行以下操作:

const embed = new Discord.MessageEmbed()
    .setTitle("Command List :")
    .setColor("GREEN");
var tempDesc = "";

for (let line of data) {
    if ((tempDesc + line).length < 1024) tempDesc += line
    else {
        message.channel.send(embed.setDescription(tempDesc));
        tempDesc = "";
    }
}

if (tempDesc.length > 0) message.channel.send(embed.setDescription(tempDesc));