javascript - 如何将普通文本和嵌入在同一条消息中?不和谐.js
问题描述
因此,我想将嵌入文本和普通文本都放在一条消息中。我想我已经看到了,但如果不可能,你可以在评论中说出来。
我尝试了一些可能很愚蠢的方法(我是编码新手)。这是我尝试的方法:
if (msg.startsWith(among + 'wiki')) {
wikipog = message.content.slice(7);
var embed = new Discord.MessageEmbed()
.setTitle(':globe_with_meridians: Among Us Wiki :globe_with_meridians:')
.setDescription('Down below is the page you asked for!')
.addField(
'If an image shows up down below, that means your page exists!',
'\u200B'
)
.addField('\u200b', field)
.setColor(color)
.setFooter(footer);
message.channel.send(embed, `https://among-us.fandom.com/wiki/${wikipog}`);
}
先感谢您!
(顺便说一句,我知道我可以做两个 message.channel.send(),但这会发送两个 pings/notifications)
解决方案
TextChannel#send
接受 2 个参数。第一个是消息内容(文本),第二个是带有选项的对象。您可以在选项对象中设置嵌入。
const Embed = new Discord.MessageEmbed()
.setTitle('Title')
.setDescription('This is an embed message')
.setColor('RED');
message.channel.send('This is a normal message.', {
embed: Embed,
});
DiscordJS 13 的更新
TextChannel#send
接受一个类型的参数string | MessagePayload | MessageOptions
。MessageOptions
允许您指定内容和嵌入:
const Embed = /* ... */;
message.channel.send({
content: 'This is a normal message.',
embeds: [Embed],
});
推荐阅读
- python - 弹性搜索请求
- regex - 在 Dart 中使用 RegEx 获取字符串的一部分
- kubernetes - StatefulSets 中的并行 podManagementPolicy 优于 OrderedReady podManagementPolicy 的优缺点是什么?
- r - Bootstrapping 95% CI 根据编码方式给出不同的值
- java - Android Studio 上的 TooManyPlayerExceptions Deezer API
- html - 使用 Ionic 3 在 Sonarqube 中意外的未知类型选择器
- mysql - 插入数据的过程中出现错误代码 1172
- c# - 通过 Azure DevOps 部署时出现错误:您无权查看此目录或页面
- java - spring boot 无法运行 oracle plsql 脚本
- javascript - Angular中的innerHTML问题