-3

I am making a Discord bot and trying to have it send images.

These are all my imports:

 import discord
from discord.ext import commands
from discord.ext.commands import Bot
import asyncio
import random
import time
import ftplib

Then I have this code:

bot = commands.Bot(command_prefix="2")

Then I have this one that when I launch my run.py it shows me some prints in the app:

@bot.event
async def on_ready():
    print("I'm running on: " + bot.user.name)
    print ("With the ID: " + (bot.user.id))
    print("The commands are \n" + "#ping \n #pong \n #info (@user) \n #embedtest \n #hello \n #hug \n #kill \n ")

This is my code for the picture, so this code should make a picture pop up from the same folder as my run.py program is located.

@bot.command(pass_context=True)
async def image(ctx):
myImage = open('UDST.png', 'rb') 
await bot.send_file(myImage)

But then when I run it, it gives me this error that I don't understand.

C:\Users\david>"C:\Users\david\Desktop\UDST Bot\Udst bot.py"
  File "C:\Users\david\Desktop\UDST Bot\Udst bot.py", line 105
    await bot.send_file(myImage)
                               ^
IndentationError: unindent does not match any outer indentation level

How do I resolve this error?

Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108
David T.
  • 1
  • 5
  • Did you have a look at similar threads in SO? See [here](https://stackoverflow.com/questions/492387/indentationerror-unindent-does-not-match-any-outer-indentation-level) and [here](https://stackoverflow.com/a/26720878/8881141) – Mr. T Dec 28 '17 at 12:14
  • Why is there no indentation? – Wright Dec 28 '17 at 18:09

1 Answers1

0

To echo what wright commented the problem is likely due to the fact you haven't indented after your function (you're getting an indentation error).

this

@bot.command(pass_context=True)
async def image(ctx):
myImage = open('UDST.png', 'rb') 
await bot.send_file(myImage)

should be this

@bot.command(pass_context=True)
async def image(ctx):
    myImage = open('UDST.png', 'rb') 
    await bot.send_file(myImage)

If that doesn't work you can try out some of the examples of sending an image as found on the discord.py docs. One of the examples shows that you can send an image just by passing the file name,

await client.send_file(channel, 'your_image_file_here.png')

Hope that solves your problem!

Milan Donhowe
  • 193
  • 1
  • 9