I’d like to make a bot, to resend an image/file sent to a channel.
The bot get’s the url of the file (message.attachments[0].url), but when I want to send it as a file, it says FileNotFoundError: [Errno 2] No such file or directory: ….png
The bot was working and resending an image one single time, but then about 50 times, it’s not.
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith("anon ") or message.content.startswith("Anon "):
if message.attachments:
await message.channel.send(f"{message.content[5:]}", file=discord.File(message.attachments[0].url))
Thank you for helping!
>Solution :
You need to convert attachment to file. You can use to_file() function like this:
await message.channel.send(f"{message.content[5:]}", file=await message.attachments[0].to_file()