I started the bot from anacomda, but after I changed it to Pycharm (anaconda), I could not call it if I issued a command to call the png file.
I may change the location of the png file, but I don't know where to put it.
Applicable source code
Ignoring exception in on_message Traceback (most recent call last): File "C:\Users\user\anaconda3\lib\site-packages\discord\client.py", line 312, in _run_event await coro(*args, **kwargs) File "C:/Users/user/PycharmProjects/discordbot/discordbot1/bot.py", line 44, in on_message await message.channel.send('a', file=discord.File('b.png')) File "C:\Users\user\anaconda3\lib\site-packages\discord\file.py", line 68, in __init__ self.fp = open(fp,'rb') FileNotFoundError: [Errno 2] No such file or directory:'b.png'
import discord TOKEN ='' client = discord.Client() @client.event async def on_ready(): print('Logged in') @client.event async def on_message(message): if message.author.bot: return if message.content =='a': await message.channel.send('a', file=discord.File('b.png')) client.run(TOKEN)
Answer # 1
I think it's better to get the current directory while running with bot, find out where it is, make an appropriate directory from it, put png in it, and specify it with a relative path when sending a file.
If you don't know any of the following terms, googling with that keyword will hit you a lot.
python current directory
python relative path
- python 3x - cannot specify display position even using python3 tkinter geometry
- python - the file cannot be read
- cannot post html form on local web server using python
- graph display method in python (matplotlib, seaborn) whether data frame transformation is necessary, etc
- python 3x - the package cannot be imported in python3 (basic learning)
- python 3x - i want to display two jpg images in python and display different images with the buttons
- python - importerror module cannot be installed from other packages
- python 3x - updated csv data display to python3 tkinter treeview
- python - i want to pass a gzip file to iot core → lambda
- python - column name cannot be changed with rename ()
- python - tkinter window display
- python - matplotlibpyplotimshow image display
- python - createtoolhelp32 cannot get the values of various registers with snapshot ()
- python - i want to display data scraped by selenium in a table using a for statement in a django template
- [python beginner] i want to display the information acquired by mediainfo using class inheritance
- i want to run a python file on windows on a mac!
- python - i can't display html with render_template as i expected
- python - japanize_matplotlib cannot be used
- python setuppy install cannot be run
- [python3] i want to enter the contents (name) of the qr code using a barcode reader
- i want to know the solution for twitter api error:401
- python 3x - how to pass path of python of anaconda
- can't install mecab-python3
- python 3x - about use of decision tree in anaconda
- i want to detect objects with python+opencv
- python 3x - is it possible to create @file: by creating with pip freeze> requirementstxt?
- python 3x - popen in subprocess does not release memory in python3 (anaconda, windows 10)
- python 3x - installed packages do not apply