Как исправить ошибку FileNotFoundError: [Errno 2] No such file or directory:?
Файл находится в директории, открывается при помощи модуля PIL
Скрипт:
@bot.command(name = "a")
async def a(ctx, *, text):
text1 = text
if len(text1) >= 30:
await ctx.send(embed = discord.Embed(description = f'{ctx.author.mention}, длина текста не должна превышать 30', colour = discord.Color.red()))
return
else:
achievement = Image.open("ach.png") #открытие файла
colors = ["white"]
drawer = ImageDraw.Draw(achievement)
font = ImageFont.truetype("F77 Minecraft.ttf", 15)
for color in colors:
drawer.text((60, 35), text = text1, font = font, fill = color)
achievement.save("exit.png")
file = discord.File("exit.png", filename = "exit.png")
embed = discord.Embed(color = discord.Colour.gold())
embed.set_image(url="attachment://exit.png")
await ctx.send(file = file , embed = embed)
Полная развертка ошибки:
Ignoring exception in command a:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/discord/ext/commands/core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "/Users/timofeitarasenko/Desktop/bebrobot/bot.py", line 144, in a
achievement = Image.open("ach.png")
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/PIL/Image.py", line 3068, in open
fp = builtins.open(filename, "rb")
FileNotFoundError: [Errno 2] No such file or directory: 'ach.png'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/discord/ext/commands/bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/discord/ext/commands/core.py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/discord/ext/commands/core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: FileNotFoundError: [Errno 2] No such file or directory: 'ach.png'