Sending Images
Last updated
Last updated
You will be learning to send images along with your other message (text, embed, etc.) and using that to make your commands more immersive.
First thing we need to do is add our image to Repl. Select any image you want to send when a user runs a command. Make sure the image is appropriate.
Now go to the sidebar and select the add folder button, as show below.
Name that folder "images" and add your image to the folder by selecting the 3 dots, then selecting "Upload File". There you can find and select your image. Drag and drop it into the images folder and name it something easy to type and something relevant to the photo.
I am going to be creating a command called photo. I will use this command to send a photo of the CoderDojo logo. To do this, you will use the same format for creating commands that you have done before.
Now all we need to do is send an image. It is very similar to how we sent the embed from last section. Use
You need to replace [name of image] with what you named the image. Lets break this piece of code down. You use the await message.channel.send
to send a message to the channel. Then you use file =
to show that you are sending a file, in this case an image. Then you use discord.File(image)
to let Discord format the image properly. The image parameter in discord.File
is the location of the image.
Did you know you can send multiple responses in one command?
Just make sure to use await before thing you send. For example
await message.channel.send(embed=embed)
await message.channel.send(file=discord.File('images/[name of image]'))
would be a valid piece of code you can add to your command as it will send both the embed and the image one after the other.
Only select the Final Code tab once you have completed your image command. If you are stuck please see a mentor.
Your code should look something like the following at this point in the sushi card, except it will contain your custom commands:
Only select the Final Code tab once you have completed this section. If you are stuck please see a mentor.
If your code is not like this or is not working, please either read through the sushi card again OR come talk to one of the mentors who will guide you through the issue.