【问题标题】:Send multiple embeds in one message with Discord.py使用 Discord.py 在一条消息中发送多个嵌入
【发布时间】:2020-04-21 02:25:42
【问题描述】:

我一直在尝试使用 discord.py 在单个消息中发送嵌入列表。

我在 discord.py 的文档中看到这是可能的:https://discordpy.readthedocs.io/en/latest/api.html

send(content=None, *, wait=False, username=None, avatar_url=None, tts=False, file=None, files=None, embed=None, embeds=None)

embeds (List[Embed]) – 与内容一起发送的嵌入列表。最多 10 个。这不能与 embed 参数混合。

但是,当我尝试将“embeds”参数传递给 send() 函数时,我收到一条错误消息:

TypeError: send() 得到了一个意外的关键字参数 'embeds'

我需要有几个嵌入,因为我想使用作者字段的图标功能,并且我需要它们在同一条消息中,因为如果用户添加反应,我想用嵌入上的另一个列表替换这些嵌入。

这是我的代码:

embedList = []
for monster in monsters:
    embed = discord.Embed(color= 0x202225)
    embed.set_author(name=monster['name'], icon_url="https://ochabot.co/sprites/16/" + str(monster["family"]) + "_" + str(monster["species"]) + "_discord.png")
    embedList.append(embed)
    if(len(embedList) == 10):
        print(embedList)
        await message.channel.send(embeds=embedList)
        embedList = []

这应该每十个怪物发送一条包含 10 个嵌入的消息。

我是 Python 新手,所以我可能只是犯了一个愚蠢的错误。感谢您的帮助!

编辑: 这是“print(embedList)”显示的内容:

[<discord.embeds.Embed object at 0x7fd3552d9dc8>, <discord.embeds.Embed object at 0x7fd3552d9e58>, <discord.embeds.Embed object at 0x7fd3552d9ee8>, <discord.embeds.Embed object at 0x7fd3552d9f78>, <discord.embeds.Embed object at 0x7fd354274048>, <discord.embeds.Embed object at 0x7fd3542740d8>, <discord.embeds.Embed object at 0x7fd354274168>, <discord.embeds.Embed object at 0x7fd3542741f8>, <discord.embeds.Embed object at 0x7fd354274288>, <discord.embeds.Embed object at 0x7fd354274318>]

【问题讨论】:

  • 你指的是这个function吗?
  • 不,我指的是this 函数。我刚刚看到它在 webhook 类别下,这是否意味着多个嵌入仅适用于 webhook ?
  • 看起来是这样,因为 message.send 函数只接受一个 embed 参数,而不是 webhook 一个
  • 哦,我明白了,谢谢你的帮助!
  • 如果解决了,你应该添加一个答案并接受它

标签: python discord.py


【解决方案1】:

这个答案只是为了完成:Discord Bot API 不允许在一条消息中发送多个嵌入。正如seen here(Minn 在 cmets 中已经提到)

embed (Embed) – The rich embed for the content.

意味着该函数只接受一个嵌入对象,而不是它们的列表。

【讨论】:

    猜你喜欢
    • 2019-10-23
    • 2021-02-13
    • 1970-01-01
    • 2019-04-14
    • 2021-07-10
    • 2021-05-01
    • 2021-09-07
    • 2021-07-08
    • 2018-01-15
    相关资源
    最近更新 更多