我有一個陣列,我想從中發送按鈕我的意思是我不知道我有多少,我已經測驗了這段代碼,但它發送了 2 條不同的按鈕訊息:
array.flatMap(user => {
const cs = new client.discord.MessageActionRow()
.addComponents(
new client.discord.MessageButton()
.setLabel(user.type)
.setURL(${user.id})
.setEmoji('979681456781635700')
.setStyle('LINK')
);
const ch = client.channels.cache.get('998376140326256158');
ch.send({
embeds: [embed],
components: [cs, ]
})
})
這是我的陣列:
[
{
id: '08933438391',
type: 'ejx1'
},
{
id: '12361425430',
type: 'ejx3'
}
]
我不知道,它可以是 4 個 id、type 或 3 或任何我不知道的(不會超過 10 個)
uj5u.com熱心網友回復:
addComponents方法可以與陣列一起使用。只需將按鈕保存在其中,然后使用該方法。請記住,每行只能設定五個按鈕。
const row = new client.discord.MessageActionRow();
let buttons = [];
for(let i = 0; i < array.length; i ){
buttons.push(
new client.discord.MessageButton()
.setLabel(array[i].type)
.setURL(${user.id})
.setEmoji(array[i].id)
.setStyle('LINK')
);
}
row.addComponents(buttons);
//Do your stuff with the row variable.
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/487460.html
標籤:javascript 数组 按钮 不和谐 不和谐.js
上一篇:在按鈕上下載檔案單擊jquery
