所以我目前有这个代码,它为我的discord bot制作了一个8ball,我有这个错误,它说“缩进错误:预期和缩进块”
以下是我正在使用的代码(请参阅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')
答案 0 :(得分: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
是变量的非法名称,因为变量名称必须以字母或下划线符号开头({ {1}})。
注意: 为了更好的可读性,长列表可以分成多行:
_
答案 1 :(得分: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)
确切地说,错误消息的内容是:缩进它。