-2

Well, I tried to send a picture from a specific folder but the bot can't find it. Is that me, I can't write code that would search a folder well. I would also like the bot to send images from the url.

Here is my code:

@commands.command()
    async def picture(self, ctx, picture):
        await ctx.send(file = discord.File(picture))
        await ctx.message.delete()

I'm just learning Python, so any help is appreciated.

Conor
  • 1
  • Are you running the bot on your computer or through an online software like a web interpreter? – EpicEfeathers Dec 15 '21 at 13:22
  • Also, would you mind posting what errors you get when you run the command? Welcome to Stack by the way! – EpicEfeathers Dec 15 '21 at 13:53
  • 3
    Does this answer your question? [Discord.py Bot sending file to Discord Channel](https://stackoverflow.com/questions/50860397/discord-py-bot-sending-file-to-discord-channel) – ChaoticNebula Dec 15 '21 at 13:58
  • I run bot on replit. – Conor Dec 15 '21 at 17:04
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Dec 22 '21 at 16:08

1 Answers1

0

You may need some code like this:

await ctx.send(file=discord.File(r'C:\location\of\the\file.png'))

discord.File objects' constructor gets as first argument the path of the file.


In you case you can edit your code like this:

async def picture(ctx, path: str) -> None:
    await ctx.send(file=discord.File(path))
    await ctx.message.delete()

If you want some more information about sending files (I read you want to send files by url too), you should write the documentation in this links:

FLAK-ZOSO
  • 3,873
  • 4
  • 8
  • 28