【问题标题】:What to embed the dynamic help command嵌入动态帮助命令的内容
【发布时间】:2020-09-19 19:00:45
【问题描述】:

所以我使用 discord 文档编写了一个动态帮助命令。但为了吸引眼球,我想将其嵌入并显示到用户 DM 中。 这是一个小sn-p -

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 吗?

【问题讨论】:

    标签: discord discord.js


    【解决方案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】:
      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));
      
      

      【讨论】:

        【解决方案3】:

        您的意思是制作一个嵌入并显示所有命令名称吗?

        无论如何我可以在嵌入中使用 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?');
              });
          }
        }
        

        【讨论】:

          猜你喜欢
          • 2021-09-16
          • 2021-01-12
          • 1970-01-01
          • 1970-01-01
          • 2021-08-20
          • 1970-01-01
          • 2011-01-12
          • 2021-01-13
          • 1970-01-01
          相关资源
          最近更新 更多