Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
486 views
in Technique[技术] by (71.8m points)

node.js - Turn queue list into an embed

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:**
${nowPlaying.songTitle}
**Requested By:**
${nowPlaying.requester}

**Queue**
`


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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try something like this:

let q = ``;
for(var i = 0; i < queue.length; i++) {
    q += `
${i + 1}. **${queue[i].songTitle}**
Requested 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,
}});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...