javascript - 如何将参数传递到嵌入中
问题描述
我正在尝试制作一个建议命令,用户可以在其中键入.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(' '))
推荐阅读
- scrollview - 如何在 SwiftUI 中使用 ScrollView(不滚动)
- python - 尝试使用 BeautifulSoup 从没有 API 的站点获取数据
- javascript - 如何通过单击一天将新事件添加到 fullcalendar.io
- python - 我如何编写代码来检查具有名称的文件(csv)是否已经存在?
- git - 使用 git 在我的存储库中找不到文件
- html - 为什么我的所有列都在一列中?
- react-native - 在 React Native 中滑动刷新以查看视图
- r - 如何聚合一列中的值以创建新列
- sql - 使用重复数据时如何创建合并 SQL
- ios - 缺少 NFCTagReaderSession 所需的权利