2017-12-28 16 views
-3

私はDiscordボットを作ってイメージを送信しようとしています。"IndentationError"を解決するにはどうすればよいですか?

これらはすべて私の輸入です:

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

その後、私はこのコードを持っている:

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

その後、私は私が私のrun.pyを起動したとき、それは私の中にいくつかの印刷物を示していること、このいずれかを持っていますアプリ:

@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 ") 

これは画像のコードなので、このコードは画像を同じ折り畳みからポップアップ表示する必要があります私のrun.pyプログラムがあるので。

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

しかし、それを実行すると、私はこのエラーを私には分かりません。

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 

どのように私はこのエラーを解決するのですか?

+0

SOに類似のスレッドがありますか? [ここ](https://stackoverflow.com/questions/492387/indentationerror-unindent-does-not-match-any-outer-indentation-level)と[ここ](https://stackoverflow.com/a/)を参照してください。 26720878/8881141) – MrT

+0

インデントがないのはなぜですか? – Wright

答えて

0

あなたの関数の後ろに字下げしていないという事実のために、問題の可能性が高いと思われるWrightの意見をエコーするには、インデントエラーが発生しています。

この

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

は、それが動作しない場合は、discord.py docsに見られるような画像を送るの例のいくつかを試してみることができます。この

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

でなければなりません。例の1つは、ファイル名を渡すだけで画像を送信できることを示しています。

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

希望が問題を解決します。

関連する問題