首页 > 解决方案 > 如何将参数传递到嵌入中

问题描述

我正在尝试制作一个建议命令,用户可以在其中键入.suggest <yoursuggestion>,并将他们的建议嵌入发送到建议频道供人们投票。
我现在唯一遇到的问题是每个论点(单词)都占用了自己的路线,我不希望这种情况发生。任何帮助是极大的赞赏。

module.exports = {
    name: 'suggest',
    aliases: ['suggestion'],
    description: 'Sends a suggestion to the <#700591796119535657> channel.',
    usage: '<your suggestion>',
    cooldown: 1,
    args: true,
    execute(message, args) {
        const Discord = require('discord.js');
        const exampleEmbed = new Discord.MessageEmbed()
            .setColor('#32CF67')
            .setTitle('Suggestion:')
            .setDescription(args)
            .attachFiles(['/home/shares/public/RetroCraft/retro.png'])
            .setThumbnail('attachment://retro.png')
            // .setTimestamp()
            .setFooter(message.member.displayName, message.author.displayAvatarURL({ format: 'png', dynamic: true }));

        // eslint-disable-next-line no-shadow
        const channel = message.guild.channels.cache.find(channel => channel.name === 'logs');
        channel.send({ embed: exampleEmbed }).then(embedMessage => {
            embedMessage.react('710672162242953266')
                .then(() => embedMessage.react('710672162393948170'))
                .then(() => embedMessage.react('710672162264055808'))
                .then(() => embedMessage.react('710672162343747607'))
                .then(() => embedMessage.react('710672162125643837'))
                .then(() => embedMessage.react('710672162171650058'))
                .catch(() => console.error('One of the emojis failed to react.'));
        });
    },
};

这就是在我的 index.js 中定义 args 命令的方式:

const args = message.content.slice(prefix.length).split(/ +/);

这是我运行时产生的消息.suggest this is a test

当我执行 <code>.suggest this is a test</code> 时产生的消息

标签: javascriptnode.jsdiscord.js

解决方案


发生这种情况是因为您将args一个数组而不是字符串传递给该.setDescription()方法。
要解决此问题,您可以使用空格连接单词数组:

exampleEmbed.setDescription(args.join(' '))

推荐阅读