Turn queue list into an embed

偶尔善良 提交于 2019-12-25 01:54:01

问题


Recently made a queue command for my bot and it works, but I'm wanting it to display in a RichEmbed.

let resp = `**Now Playing:**\n${nowPlaying.songTitle}\n**Requested By:**\n${nowPlaying.requester}\n\n**Queue**\n`


for (var i = 1; i < queue.length; i++) {
    resp += `${i}. **${queue[i].songTitle}**\n**Requested By:** ${queue[i].requester}\n`
}

This is the current code I have set to display the queue. Now, my exact problem is resp +=. I know that each time a song is added to the queue and the command is rerun, it will have it listed as it is in the queue, but I'm still teaching myself Node.JS, so this is a little more difficult to solve, as I've never had any commands that use += to send an updated message.


回答1:


Try something like this:

let q = ``;
for(var i = 0; i < queue.length; i++) {
    q += `\n${i + 1}. **${queue[i].songTitle}**\nRequested By: ${queue[i].requester}`;
}
let resp = [
    {name: `Now Playing`, value: nowPlaying.songTitle},
    {name: `Requested By`, value: nowPlaying.requester},
    {name: `Queue`, value: q},
];

//Putting it all together
message.channel.send({embed: {
    title: 'Queue',
    fields: resp,
}});


来源:https://stackoverflow.com/questions/51354201/turn-queue-list-into-an-embed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!