如何在使用for循环时不发送垃圾邮件

2024-03-28 23:00:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在制作一个音乐机器人,目前我打算添加一个队列命令,显示队列中的所有歌曲

upcoming = list(itertools.islice(player.queue._queue, 0, 9))
counter = 1

for song in upcoming:
    counter = counter + 1
    print(f"{counter}. {song['title']}")
    embed = discord.Embed(description=f"**{counter}**. [{song['title']}]({song['url']})")
    embed.set_thumbnail(url=self.bot.user.avatar_url)
    embed.set_author(name="Playing Next:")
    await ctx.send(embed=embed)

这就是我所期望的:

1. Song 1
2. Song 2
3. Song 3 
4. Song 4
5. Song 5 
6. Song 6
7. Song 7
8. Song 8
9. Song 9

相反,它以单独的嵌入方式发送每一行


Tags: 命令url队列queuesongtitle音乐counter
1条回答
网友
1楼 · 发布于 2024-03-28 23:00:20

您正在创建一个新的嵌入并为循环的每个迭代发送它。在不理解列表的情况下,最简单的解决方案是将所有内容移出for循环,除了以下内容:

embed = discord.Embed(description='')

for song in upcoming:
    embed.description += f"**{counter}**. [{song['title']}]({song['url']})\n"

... other embed stuff
... await send embed

相关问题 更多 >