bots - 试图在 discord.js 嵌入机器人的列中显示玩家名称
问题描述
嘿伙计们,我想弄清楚如何嵌入一个基本上显示团队名册的机器人,但我不知道如何在列中制作团队球员的名字。我尝试将其放入 .addfield 中,但没有奏效。这是我正在尝试做的一个例子1
case 'roster':
const roster = new Discord.MessageEmbed()
.setTitle('FinalSpark')
.setDescription('Rank: 3 | Region: EU | League: CCL')
.setURL('https://club.mpcleague.com')
.setFooter('bot made by alex :D')
.addField('Roster')
message.channel.send(roster);
break;
解决方案
看起来嵌入使用了两个字段,第二个字段的标题为空白
您应该这样做的方法是首先将您的花名册列表放入一个数组中,然后将数组分成两半:
//your roster array
const roster = [];
//round up so the first row always either has equal or more items
//use Math.floor() if you want the opposite
const midIndex = Math.ceil(roster.length / 2);
const firstRow = roster.slice(0, midIndex);
const secondRow = roster.slice(midIndex);
const embed = new Discord.MessageEmbed()
.setTitle('FinalSpark')
.setDescription('Rank: 3 | Region: EU | League: CCL')
.setURL('https://club.mpcleague.com')
.addField("Roster", firstRow.join("\n"), true);
if (secondRow.length) {
// \u200b is what makes the invisble effect, you can have \u200b
// for both the key and value which would essentially make a blank line
embed.addField("\u200b", secondRow.join("\n"), true);
}
message.channel.send(embed);
当然,那将在案例陈述中。
推荐阅读
- python - 从字符串在python中创建一个列表
- android - Flutter 中的 Dialogflow 建议芯片响应?
- javascript - 一次仅扩展一个移动导航选项
- python - 优化旅行推销员算法(时间旅行者算法)
- r - 如何使用向量对数据帧列表进行子集化
- excel - 将工作表复制到 ActiveWorkbook
- python - 将校正列添加到数据框
- go - 为 Windows 编译带有 C 依赖的 go 程序
- node.js - Golang:使用 node.js 等可读流从 PostgreSQL 数据库中选择几百万行
- html - 如何在 App 而不是浏览器中打开 Facebook like 按钮确认对话框?