1

I want to make a bot that sends pictures from a folder (i dont really know how to explain) The file named bot.py is the bot's code and I want the bot to send pictures from the outfit folder (I don't want to upload the pictures to imgur or something like that).

Here is my bot's code:

import os
import random
import discord

from discord.ext import commands
from dotenv import load_dotenv

load_dotenv()
token = os.getenv('DISCORD_TOKEN')
guild = os.getenv('DISCORD_GUILD')

bot = commands.Bot(command_prefix='!')

@bot.command(name='test')
async def test(ctx):
    test = [
        ('Testing Message'


        )

    ]

    response = test
    await ctx.send(response)
@bot.event
async def on_member_join(member):
    role = discord.utils.get(member.guild.roles, name="server-doll")
    await member.add_roles(role)


@bot.event
async def on_ready():
  print("Bot Connected Perfectly")


bot.run(token)
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Wolly ZR
  • 15
  • 3

1 Answers1

3

https://discordpy.readthedocs.io/en/latest/faq.html#how-do-i-upload-an-image

await channel.send(file=discord.File('my_file.png'))

or

with open('my_file.png', 'rb') as fp:
    await channel.send(file=discord.File(fp, 'new_filename.png'))

If you are having problems building a relative path to your image file look into this Stackoverflow question.

Tin Nguyen
  • 5,250
  • 1
  • 12
  • 32