SAL
SAL

Reputation: 545

Sending multiple files in discord Embed - discord.py

For now, I have sent files via link (image below), but for security reasons I can't anymore. File via link

A first idea that came to me is to send one file at a time in different messages, but I don't like it.

So, there is a way to send multiple files in a Discord embed (Or multiple files in a single message)?

Upvotes: 0

Views: 2879

Answers (1)

TheFungusAmongUs
TheFungusAmongUs

Reputation: 1516

Explanation

This can be accomplished by making a list of discord.File objects, then passing it as Messageable.send(files=your_list_of_files).

I've included code below which opens a list of file objects based on their filenames.

Code

files_to_read: list[str] = []
files_to_send: list[discord.File] = []
for filename in files_to_read:
    with open(filename, 'rb') as f:  # discord file objects must be opened in binary and read mode
        files_to_send.append(discord.File(f))
await {Messageable}.send(files=files_to_send)

Reference

discord.File

Messageable.send

Upvotes: 1

Related Questions