Skip to content
Sign upLog in
← Back to Community

How to I import an image and use it to make a Discord bot?

Profile icon
Nithen

So, I'm making a Discord bot and I want to make a bot that sends pictures of dragons when the user types "$dragon". So far, I have one image, and I have uploaded it to the Repl file tab. However, I don't know how to import the .gif file to my main.py file. Please help me! I'm very new to Python and coding as a whole...

Voters
Profile icon
Nithen
Comments
hotnewtop
Profile icon
SixBeeps

Discord.py's send() method has an option for passing in files. Here's what it looks like:

await channel.send(file=discord.File('my_image.gif'))

As long as you have the channel that they sent the message through, this will send the image in the same channel.

Profile icon
Nithen

@SixBeeps
I tried it, and its showing undefined name 'channel'. Should I give the name of the channel or something? Thanks in advance!

Profile icon
SixBeeps

@Nithen
If you're using on_message, you can get the channel with message.channel. Is it possible for you to link the Repl?

Profile icon
Nithen

@SixBeeps
yea sure.. but it's very long
Go near the last line to find the error-
https://repl.it/@Nithen/Hawk#main.py