(я использую Python 3.9.5)вот код:
import os
import random
import sys
import time
from os import listdir, path
from os import system
import discord
from discord.ext import commands
from progress.bar import IncrementalBar
client = commands.Bot(command_prefix='!')
token = open('token.txt', 'r').readline()
@client.command(pass_context=True)
async def Imgs(ctx, *args, **kwargs):
author = ctx.message.author
await ctx.send(file=discord.File(random.choice(os.listdir('images/'))))
print('User ' + f'{author} use command: !Imgs')
client.run(token)
и код ошибки при вводе команды:
- Ignoring exception in command Imgs:
- Traceback (most recent call last):
- File "C:\Python39\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
- ret = await coro(*args, **kwargs)
- File "C:\Users\1337pro8\Desktop\discord-bot\PTB\bot02.py", line 74, in Imgs
- await ctx.send(file=discord.File(random.choice(os.listdir('images/')))) # отрпавляет любую картинку из папки на ПК в чат дискорда
- File "C:\Python39\lib\site-packages\discord\file.py", line 73, in __init__
- self.fp = open(fp, 'rb')
- FileNotFoundError: [Errno 2] No such file or directory: 'Screenshot_20210701-222444_Instagram.jpg'
- The above exception was the direct cause of the following exception:
- Traceback (most recent call last):
- File "C:\Python39\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke
- await ctx.command.invoke(ctx)
- File "C:\Python39\lib\site-packages\discord\ext\commands\core.py", line 863, in invoke
- await injected(*ctx.args, **ctx.kwargs)
- File "C:\Python39\lib\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: 'Screenshot_20210701-222444_Instagram.jpg'