我正在尝试创建一个建议命令,用户将在其中键入.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
时得到的消息
之所以会这样,是因为您将args
(它是一个数组而不是一个字符串)传递给.setDescription()
方法。要解决这个问题,您可以使用空格将单词数组连接起来:
exampleEmbed.setDescription(args.join(' '))