python中的elif语法无效
我正在尝试学习如何使用python,我一直想制作我自己的discrod机器人,所以我尝试使用discord.py,但我添加了elif使其更加优化,因此如果没有命令通过,但使用了正确的前缀,则会显示一条帮助消息,但不知怎的,我的elif语法错误,这是我的代码错误在第33行,如果这有区别,我就用replitpython中的elif语法无效,python,discord.py,bots,Python,Discord.py,Bots,我正在尝试学习如何使用python,我一直想制作我自己的discrod机器人,所以我尝试使用discord.py,但我添加了elif使其更加优化,因此如果没有命令通过,但使用了正确的前缀,则会显示一条帮助消息,但不知怎的,我的elif语法错误,这是我的代码错误在第33行,如果这有区别,我就用replit import discord import os import random from random import randint client = discord.Client() @cl
import discord
import os
import random
from random import randint
client = discord.Client()
@client.event
async def on_ready():
print('Logged in as {0.user}'.format(client))
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('%%'):
if message.content.startswith('%%help'):
embedVar = discord.Embed(title="Commands", description="Fine here's a list of commands", color=0x00ff00)
embedVar.add_field(name="%%coin", value="randomly says heads or tails", inline=True)
embedVar.add_field(name="%%messagedev", value="sends me a message that I unfortanatly cannot repond to", inline=True)
embedVar.add_field(name="%%die @exaple", value="puts a funny message with whoever you @ dying", inline=True)
embedVar.add_field(name="%%wrk", value="randomly gives you money that you immediatly burn because it wont be saved cause I haven't yet made a system to record you balence", inline=True)
await message.channel.send(embed=embedVar)
elif message.content.startswith('%%coin'):
await message.channel.send(random.choice(['Heads','tails']))
elif message.content.startswith('%%messagedev'):
dmes = message.content.replace("%%messagedev","")
print(('{}:{}').format([(message.author.name),(dmes)])
elif message.content.startswith('%%die'):
dinput = message.content.replace("%%die","")
await message.channel.send(random.choice(['looks like{} got deadified'.format(dinput), 'looks like{} got 360 no scoped'.format(dinput), 'looks like{} got totally rekt and died'.format(dinput)]))
elif message.content.startswith('%%wrk'):
rrnngg = (randint(1,500))
rand = random.choice(["DANG! he be working you earn {}$ that you immediatly burn because it wont be saved cause I haven't yet made a system to record you balence".format(rrnngg), "DANG! he be not working you earn 0$""])
await message.channel.send('{}'.format(rand))
else: await message.channel.send('Hey not sure if mispled or whatever but for help use %%help')
client.run(os.getenv('TOKEN'))
Barmar在那之前通知我,我在这行中缺少a),只是将其作为答案发布,这样我就可以将此标记为已解决。你在这之前的行中缺少a
)
。使用一个自动检查平衡括号的IDE。我不敢相信我没有注意到我花了这么多时间思考我的缩进有问题打吧,谢谢你!