python - python中的elif语法无效
问题描述
我正在尝试学习如何使用 python,我一直想制作自己的 discrod 机器人,所以我尝试使用 discord.py 但我添加了 elif 来使它更加优化,所以如果没有命令通过但正确使用前缀,然后通过帮助消息,但不知何故我的 elif 语法错误,这是我的代码,错误在第 33 行,如果有差异,我使用 replit
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 通知我,在此之前我在线上缺少一个 ),只是将其发布为答案,以便我可以将其标记为已解决。
推荐阅读
- php - 如何在laravel中获取上个月的订单商品销售报告?
- sql - 根据列中的最近日期从表中获取过去 6 个月的数据
- mysql - GROUP BY 计数也缺少类型(Maria DB)
- terraform - 通过批处理提交来改造不同的行为
- katalon-studio - 可以在 Katalon Studio 中创建自定义标记视图吗?
- javascript - 如何在回调函数中处理异步响应?
- python - WordUnderCursor 无法正常工作(未在任何单词之上时检测到单词)
- javascript - 找不到 ECMAScript 提到关于作用域链的地方
- python - Django 测试失败并显示“没有用户匹配给定的查询”。
- windows - 我可以在 Windows 10 S 模式下本地安装 UWP 应用吗?