2017-10-09 107 views
-1

,所以我現在有這樣的代碼,這使得一個很可能很可能對我的不和諧機器人,我有這個錯誤的地方說:「齒痕錯誤:預期和縮進塊」博特代碼錯誤:預期的縮進塊

下面是我使用的代碼(見https://hastebin.com/isageyoqih.py

import discord 
import asyncio 
import random 
import pickle 
import os 

client = discord.Client() 

@client.event 
async def on_ready(): 
    print('Ready and with') 
    print(client.user.name) 

@client.event 
async def on_message(message): 
    if message.content.startswith('_whatcanyoudo?'): 
     msg = await client.send_message(message.channel, '```Heres what i can do :```') 
     await asyncio.sleep(0.5) 
     msg2 = await client.send_message(message.channel, '```For now, i can only do a thing called "flip a coin"```') 
     await asyncio.sleep(0.5) 
     msg3 = await client.send_message(message.channel, '```Bot powered by Ouindoze™, message will delete in 15 seconds```') 
     await asyncio.sleep(15) 
     await client.delete_message(msg) 
     await client.delete_message(msg2) 
     await client.delete_message(msg3) 


    elif message.content.startswith('_8ball'): 
    8ball = random.choice(['It is certain','As i see it, yes', 'Dont count on it', 'Without a doubt', 'Definitely', 'Very doubtful', 'Outlook not so good', 'My sources say no', 'My reply is no', 'Most likely', 'You may rely on it', 'Ask again later']) 
    msg5 = await client.send_message(message.channel, 8ball) 

client.run('I obiously won't share the token duh xd') 

Here is the error I got

回答

0
elif message.content.startswith('_8ball'): 
8ball = random.choice(['It is certain','As i see it, yes', 'Dont count on it', 'Without a doubt', 'Definitely', 'Very doubtful', 'Outlook not so good', 'My sources say no', 'My reply is no', 'Most likely', 'You may rely on it', 'Ask again later']) 
msg5 = await client.send_message(message.channel, 8ball) 

應該是(elif後注壓痕)

elif message.content.startswith('_8ball'): 
    8ball = random.choice(['It is certain','As i see it, yes', 'Dont count on it', 'Without a doubt', 'Definitely', 'Very doubtful', 'Outlook not so good', 'My sources say no', 'My reply is no', 'Most likely', 'You may rely on it', 'Ask again later']) 
    msg5 = await client.send_message(message.channel, 8ball) 

,並順便說一下,8ball是非法的名字一個變量作爲變量名已經開始與下劃線符號_)。

注: 長的列表可以在多行以提高可讀性分裂:

ball = random.choice([ 
     'It is certain', 
     'As i see it, yes', 
     'Dont count on it', 
     'Without a doubt', 
     'Definitely', 
     'Very doubtful', 
     'Outlook not so good', 
     'My sources say no', 
     'My reply is no', 
     'Most likely', 
     'You may rely on it', 
     'Ask again later' 
     ]) 
+0

這樣的問題應該已經被評論和投票結束爲一個簡單的印刷錯誤。由於這個問題不會對未來的讀者有所幫助,除了OP – abccd

+0

非常感謝,我已經在這個2小時xD – Ouindoze

0
elif message.content.startswith('_8ball'): 
    8ball = random.choice(['It is certain','As i see it, yes', 'Dont count on it', 'Without a doubt', 'Definitely', 'Very doubtful', 'Outlook not so good', 'My sources say no', 'My reply is no', 'Most likely', 'You may rely on it', 'Ask again later']) 
    msg5 = await client.send_message(message.channel, 8ball) 

那麼它到底是什麼錯誤消息說:縮進它。