Home>

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.

Current file position

C:/Users/user/PycharmProjects/discordbot/discordbot1/bot.py
C:/Users/user/PycharmProjects/discordbot/discordbot1/b.png

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'
Applicable source code
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)
Supplementary information

Win10
Python3.7
pycharm×anaconda3

  • 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