Python Forum
ValueError: I/O operation on closed file problem
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ValueError: I/O operation on closed file problem
#1
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.
Reply


Messages In This Thread
ValueError: I/O operation on closed file problem - by aliwien - Apr-23-2021, 05:50 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  This result object does not return rows. It has been closed automatically dawid294 6 1,121 Mar-30-2024, 03:08 AM
Last Post: NolaCuriel
  A question about 'Event loop is closed' fc5igm 2 2,246 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,445 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,541 Aug-30-2020, 08:14 AM
Last Post: glestwid
  Inclusive (closed) range with float numbers mapg 4 4,023 Apr-27-2019, 09:09 PM
Last Post: Gribouillis
  VMware View - Session opened/closed? hhh 0 2,344 May-31-2018, 10:10 AM
Last Post: hhh
  script closed before i can see the error that occurs? wrestlemy69 9 9,266 Dec-02-2016, 01:40 AM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020