import random import discord from discord.ext import commands cad = commands.cad() my_files=[discord.File('A:\\mar\\as.jpg'), discord.File('A:\\mar\\sa.jpg'), discord.File('A:\\mar\\ar.jpg')] chosen_image=random.choice(my_files) bat = ['dog', 'cat', 'lion'] @Bot.event async def on_message(msg): . . . if any(word in msg for word in bat): await message.channel.send(file=chosen.image)My purpose is create a discord bot who sends a random photo from a folder when it sees a specific word in message. Thus, I wrote this code and when I run this code, it work in first message but then for second, ı faced with ValueError: I/O... error. How can I fix that? Can you write true code? Thank you.
ValueError: I/O operation on closed file problem
Possibly Related Threads… | |||||
Thread | Author | Replies | Views | Last Post | |
This result object does not return rows. It has been closed automatically | dawid294 | 6 | 1,005 |
Mar-30-2024, 03:08 AM Last Post: NolaCuriel |
|
A question about 'Event loop is closed' | fc5igm | 2 | 2,201 |
Oct-05-2021, 02:00 AM Last Post: fc5igm |
|
Saving text file with a click: valueerror i/o operation on closed file | vizier87 | 5 | 4,394 |
Nov-16-2020, 07:56 AM Last Post: Gribouillis |
|
Run an app in a standalone terminal and wait until it's closed | glestwid | 2 | 2,511 |
Aug-30-2020, 08:14 AM Last Post: glestwid |
|
Inclusive (closed) range with float numbers | mapg | 4 | 3,971 |
Apr-27-2019, 09:09 PM Last Post: Gribouillis |
|
VMware View - Session opened/closed? | hhh | 0 | 2,324 |
May-31-2018, 10:10 AM Last Post: hhh |
|
script closed before i can see the error that occurs? | wrestlemy69 | 9 | 9,229 |
Dec-02-2016, 01:40 AM Last Post: snippsat |
Users browsing this thread: 1 Guest(s)