[英]How do you send more than one embed per Interaction in Discord.py?
I want to make a Discord interaction that sends a picture for as often as you say in 'howmany', but with my current code it send 1 embed with a picture and the rest without one.我想进行 Discord 交互,发送图片的频率与您在“多少”中所说的一样多,但使用我当前的代码,它发送 1 个嵌入图片,而 rest 不发送图片。 How to fix this?
如何解决这个问题?
@tree.command(name='embed', description='embed')
async def embed(interaction: discord.Interaction, seeable: bool, howmany: typing.Optional[int]):
embed = discord.Embed(title="Here is a title", color=0xff8c00)
file = discord.File(f"[file path]", filename="image.png")
embed.set_image(url="attachment://image.png")
if seeable == True:
await interaction.response.send_message(file=file, embed=embed)
if howmany >= 2:
for i in range(howmany-1):
await interaction.followup.send(file=file, embed=embed)
if seeable == False:
await interaction.response.send_message(file=file, embed=embed, ephemeral=True)
if howmany >= 2:
for i in range(howmany-1):
await interaction.followup.send(file=file, embed=embed, ephemeral=True)
it already works perfectly fine without the interaction, just like the old prefix system.它在没有交互的情况下已经工作得很好,就像旧的前缀系统一样。 If you remove all the # it will upload the files from a file path.
如果您删除所有 # 它将从文件路径上传文件。 Otherwise it will show a Picture from a website:
否则它将显示来自网站的图片:
if message.content.startswith('+image'):
count = 0
args = message.content.split(' ')
if len(args) < 2:
count = 1
else:
if args[1].isdigit():
count = int(args[1])
else:
await message.channel.send("How many should it be?")
for i in range(count):
random = random.randint(1,68)
embed = discord.Embed(title="Title", color=0xff8c00)
embed.set_image(url=f"https://www.awebsite/pic{random}.png")
#file = discord.File(f"C:a/file/path/pic{random}.png", filename="image.png")
#embed.set_image(url="attachment://image.png")
#await message.channel.send(file=file, embed=embed)
await message.channel.send(embed=embed)
Have a close look at the docs for send_message
: https://discordpy.readthedocs.io/en/stable/interactions/api.html?highlight=send_message#discord.InteractionResponse.send_message仔细查看
send_message
的文档: https://discordpy.readthedocs.io/en/stable/interactions/api.html?highlight=send_message#discord.InteractionResponse.send_message
Parameters:
参数:
embeds (List[Embed]) – A list of embeds to send with the content.
embeds (List[Embed]) – 与内容一起发送的嵌入列表。 Maximum of 10. This cannot be mixed with the embed parameter.
最多 10 个。这不能与嵌入参数混合使用。
embed (Embed) – The rich embed for the content to send.
embed (Embed) – 要发送的内容的丰富嵌入。 This cannot be mixed with embeds parameter.
这不能与 embeds 参数混合使用。
In other words: if you want to send multiple embeds, use the embeds
-kwarg instead of embed
, and pass in a list of embeds you want to send.换句话说:如果你想发送多个嵌入,使用
embeds
-kwarg 而不是embed
,并传入你想要发送的嵌入列表。
...send_message(..., embeds=[embed1, embed2, embed3])
You can do the same thing when sending regular messages (not replying to interactions).您可以在发送常规消息(而不是回复交互)时做同样的事情。
Sadly the community hasn't responded yet so I fixed the bug myself.遗憾的是社区还没有回应,所以我自己修复了这个错误。 I know it's not the most beautiful code so if you have a prettier way, please let me know.
我知道这不是最漂亮的代码,所以如果您有更漂亮的方法,请告诉我。
@tree.command(name='embed', description='embed')
async def embed(interaction: discord.Interaction, seeable: bool, menge: typing.Optional[int]):
if seeable == True:
zufall = random.randint(1, 68)
embed = discord.Embed(title="embed", color=0xff8c00)
file = discord.File(f"C:/file/path/pic{zufall}.png", filename="image.png")
embed.set_image(url="attachment://image.png")
await interaction.response.send_message(file=file, embed=embed)
if menge >= 2:
for i in range(menge - 1):
zufall = random.randint(1, 68)
embed = discord.Embed(title="embed", color=0xff8c00)
file = discord.File(f"C:/file/path/pic{zufall}.png", filename="image.png")
embed.set_image(url="attachment://image.png")
await interaction.response.send_message(file=file, embed=embed)
if seeable == False:
zufall = random.randint(1, 68)
embed = discord.Embed(title="embed", color=0xff8c00)
file = discord.File(f"C:/file/path/pic{zufall}.png", filename="image.png")
embed.set_image(url="attachment://image.png")
await interaction.response.send_message(file=file, embed=embed, ephemeral=True)
#await interaction.response.send_message(embed=embed)
if menge >= 2:
for i in range(menge - 1):
zufall = random.randint(1, 68)
embed = discord.Embed(title="embed", color=0xff8c00)
file = discord.File(f"C:/file/path/pic{zufall}.png", filename="image.png")
embed.set_image(url="attachment://image.png")
await interaction.response.send_message(file=file, embed=embed, ephemeral=True)
I hope I'll help someone else with that.我希望我能帮助别人。 Ihr seids soiche Heisln.
Ihr seids soiche Heisln。
You can remove the "if seeable" condition and just put seeable to ephemeral like this:您可以删除“if seeable”条件,然后像这样将 seeable 设置为 ephemeral:
@tree.command(name='embed', description='embed')
async def embed(interaction: discord.Interaction, seeable: bool, menge: typing.Optional[int]):
embed = discord.Embed(title="Here is a title", color=0xff8c00)
file = discord.File(f"[file path]", filename="image.png")
embed.set_image(url="attachment://image.png")
await interaction.response.send_message(file=file, embed=embed, ephemeral=seeable)
if menge >= 2:
for i in range(menge - 1):
await interaction.followup.send(file=file, embed=embed, ephemeral=seeable)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.