T
T
typical_user102020-09-20 19:47:37
Python
typical_user10, 2020-09-20 19:47:37

How to fix sending a random picture?

Please tell me what is wrong.
I wrote a code that is supposed to send a random image, but I can't figure out what the problem is. I'm still pynood.

Thank you.

my_img = [
    discord.File('...'), # 1 картинка
    discord.File('...') # 2 картинка
    ]

@client.command()
async def test(ctx):
    await ctx.send(files= random.choice(my_img))


spoiler
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: object of type 'File' has no len()

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
kirillinyakin, 2020-09-20
@typical_user10

Most likely files takes a list based on the 's at the end.

R
Rodion, 2020-09-20
@rodion4dev

Hey!
The send API
The files parameter accepts a list of files, not a single object; under the hood, the library tries to calculate the amount to be passed, which it fails to do....
You can use the file parameter if it's a single object.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question