【问题标题】:Turn a queue either into embed or one single message将队列转换为嵌入消息或单个消息
【发布时间】:2021-07-23 16:30:07
【问题描述】:

我的音乐机器人中有这个队列代码:

else if(cmd === 'ws'){
            message.channel.send('Warteschlange:')
            for(i = 0; i < server_queue.songs.length; i++){
                message.channel.send('***' + (i+1) + ': ' + server_queue.songs[i].title + '***');
            }
        }

现在我想做一个 for 循环来向嵌入添加字段,或者以某种方式在其中获取一个 \n,这样我的机器人就不必为队列中的每首歌曲发送消息。 (注意:cmd === 'ws' 用于命令为“ws”时(德语缩写为队列)

【问题讨论】:

  • 那么您究竟需要什么帮助?

标签: discord.js


【解决方案1】:

您已经确定了概念,迭代每个值,然后您所要做的就是将其放入嵌入上下文中。

我基本上创建了一个新的嵌入,预先标记了作者、颜色、缩略图和时间戳。然后我遍历 server_queue 数组,然后对于每首歌曲,我会在嵌入中添加一个字段来表示该歌曲。

这是您可以使用的示例代码。您必须根据当前需要对其进行修改。您可以考虑将歌曲的艺术家添加为字段中的第二个值。我只是写了“别的东西”作为填充物。

代码:

if (command === 'ws') {
    let server_queue = ['test1', 'test2', 'test3', 'test4', 'test5']
    let embed = new Discord.MessageEmbed()
        .setAuthor("Warteschlange:")
        .setColor("#000000")
        .setThumbnail(client.user.avatarURL())
        .setTimestamp(Date.now());
    
    server_queue.forEach(song => {
        embed.addField(song, 'something else')
    })
    message.channel.send(embed);
}

【讨论】:

    猜你喜欢
    • 2021-10-09
    • 2021-09-10
    • 1970-01-01
    • 2011-07-07
    • 1970-01-01
    • 2020-07-31
    • 2011-02-18
    • 1970-01-01
    • 2023-03-27
    相关资源
    最近更新 更多