javascript - 如何从数组 discord.js 添加嵌入消息?
问题描述
我制作了一个关于真心话大冒险的机器人。当我键入 +t 时,它会发送我添加的事实之一。现在我想发送真相或敢于嵌入喜欢这个 嵌入真相或敢于
那么我该怎么做呢?请记住,我将使用嵌入我的代码来回复数组中的随机数据
// Array of possible truth replies
const t = [
"If you could be invisible, what is the first thing you would do?",
"What's the strangest dream you've ever had?",
"What are the top three things you look for in a boyfriend/girlfriend?",
"What is your worst habit?",
"How many stuffed animals do you own?",
"What is your biggest insecurity?"
];
// Array of possible dare replies
const d = [
"Do a free-style rap for the next minute.",
"Let another person post a status on your behalf.",
"Hand over your phone to another player who can send a single text saying anything they want to anyone they want.",
"Let the other players go through your phone for one minute.",
"Smell another player's armpit",
"Smell another player's barefoot.",
"Tell everyone your honest opinion of the person who sent this command."
];
// Handle all commands here
client.on('message', message => {
// Don't reply to itself
if (message.author.id === client.user.id) return;
// If there is no + (prefix) at the beginning of the message, exit function
if (!message.content.startsWith(prefix)) return;
// Remove the prefix from the message -> our command
const command = message.content.substring(prefix.length);
// Match the command
if (command === "t") { // Truth
const truth = t[Math.floor(Math.random() * t.length)];
message.channel.send(truth);
} else if (command === "d") { // Dare
const dare = d[Math.floor(Math.random() * d.length)];
message.channel.send(dare);
} else if (command === "help") { // Help
const help = new Discord.MessageEmbed()
.setColor('#72dfa3')
.setTitle(`Truth Or Dare`)
.addFields(
{ name: '``+help``', value: 'For help' },
{ name: '``+t``', value: 'For Truth' },
{ name: '``+d``', value: 'For Your Dare' },
{ name: '``Created By``', value: 'AlpHa Coder [Labib Khan]' },
)
.setTimestamp()
.setFooter(`${message.author.username}`, message.author.displayAvatarURL());
message.channel.send(help);
} else { // No match found, invalid command
message.channel.send("Invalid command, type `+help` for help.");
}
});
解决方案
好吧,您只需要像在帮助命令中那样使用嵌入。
这里的代码:
if (command === "t") { // Truth
const truth = t[Math.floor(Math.random() * t.length)];
message.channel.send(new Discord.MessageEmbed()
.setTitle("Truth")
.setDescription(truth));
} else if (command === "d") { // Dare
const dare = d[Math.floor(Math.random() * d.length)];
message.channel.send(new Discord.MessageEmbed()
.setTitle("Dare")
.setDescription(dare));
}
推荐阅读
- oracle - Oracle APEX 20.2 交互式网格中级联 LOV(基于 Web 源构建)的问题
- xml - XSLT 2.0:XPath 条件未按预期进行节点选择
- sql - Athena 中的 SQL 错误代码 您的查询有以下错误: SYNTAX_ERROR: line 5:8: Column 'amount' cannot be resolved
- asp.net-web-api - 我无法在我的 Web API 中访问使用 Postman 中的 FormData 发布的文件。HttpContext.Current.Request.Params["document"] 返回 NULL
- javascript - 在滚轮事件而不是滚动时使导航栏链接处于活动状态?
- node.js - Express & csvtojson:“未处理的拒绝错误 [ERR_STREAM_WRITE_AFTER_END]:结束后写入”
- php - 将多个文件上传到一篇文章
- php - 如果不在网址中,则正则表达式删除数字
- java - 如何通过 Java 在 ZPL 中打印中文和西里尔字符?
- python - 我的 spark rdd.take() 执行时间过长。我需要它来处理列表中的 11600 个元素