Killian Guilland
Killian Guilland

Reputation: 13

Send multiple embeds in one message with Discord.py

I've been trying to send a list of embeds in a single message using discord.py.

I've seen it was possible in discord.py's documentation: 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]) – A list of embeds to send with the content. Maximum of 10. This cannot be mixed with the embed parameter.

However, I get an error message when I try to pass the "embeds" parameter to the send() function:

TypeError: send() got an unexpected keyword argument 'embeds'

I need to have several embeds because I'd like to use the author field's icon feature, and I need them in the same message because I want to replace these embeds by another list on embeds if the user adds a reaction.

Here's my code :

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 = []

This is supposed to send a single message containing 10 embeds every ten monsters.

I'm new to Python so I might have just made a stupid mistake. Thank you for your help!

EDIT : Here is what "print(embedList)" displays :

[<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>]

Upvotes: 1

Views: 13636

Answers (2)

red78massive1573
red78massive1573

Reputation: 124

I think there is a confusion here. It is very possible to send multiple embeds in one message. From the code, I see that you didn't add a title, because a title embed is a required field. A simple fix for the code you gave us would be:

embedList = []
for monster in monsters:
    embed = discord.Embed(title="Monster Info", 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 = []

I added title="" in third line. The title field can be anything you like as long as it has a text in it. And maybe update your dpy to >2.0

Upvotes: 2

chluebi
chluebi

Reputation: 1829

This answer is only for the sake of completion: The Discord Bot API allows for no way of sending multiple embeds in one message. As seen here (and already mentioned in the comments by Minn)

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

Meaning the function only accepts an embed object, not a list of them.

Upvotes: 2

Related Questions