除了语法错误不正确不协调py



每次运行此代码时,它都会说语法错误,除了^但我的代码中没有任何内容表明为什么这不起作用我在网上找不到解决方案我的代码完全按照我在教程中看到的那样编写,我观看了这个命令

error: except asyncio.TimeoutError: ^ SyntaxError: invalid syntax

@bot.command(name="echo", description="command test")
async def echo(self, ctx):
await ctx.message.delete()
embed = discord.Embed(title="tell me wtf is up", description="timeout request")
sent = await ctx.send(embed=embed)
try:
msg = await self.bot.wait_for("message", timeout=30, check=lambda message: message.author == ctx.author and message.channel == ctx.channel)
if msg:
await sent.delete()
await msg.delete()
await ctx.send(msg.content)
except asyncio.TimeoutError:
await sent.delete()
ctx.send("cancelling due to timeout", delete_after=10)

except需要跟随相应的try块。也就是说,它需要有相同的缩进:

try:
msg = await self.bot.wait_for("message", timeout=30, check=lambda message: message.author == ctx.author and message.channel == ctx.channel)
if msg:
await sent.delete()
await msg.delete()
await ctx.send(msg.content)
except asyncio.TimeoutError:
await sent.delete()
ctx.send("cancelling due to timeout", delete_after=10)

最新更新