【问题标题】:"Expected an indented block" error while coding python for discord bot [closed]为不和谐机器人编码python时出现“预期缩进块”错误[关闭]
【发布时间】:2018-12-20 18:58:46
【问题描述】:

我的代码出现了一些错误:

import discord
from discord.ext.commands import Bot
from discord.ext import commands
import asyncio


client = commands.Bot(command_prefix = "!")


@client.event
async def on_ready():
    print("Bot is online")


@client.command()
async def raid(ctx):
while True:
await ctx.send("""@Raider come show some support and join the raid!
Meet: (link1)
Target: (link2)
Raid Call: """)
await asyncio.sleep(5)




client.run("token")

当我运行代码时,我得到:

【问题讨论】:

  • 请在问题中包含您的代码和错误。另外,请保持问题简单明了,并且只提供与您的问题相关的内容。
  • 缩进while True:之后的内容
  • 已修复,感谢您的帮助。

标签: python bots discord


【解决方案1】:

好像是这个部分:

async def raid(ctx):
while True:
await ctx.send("""@Raider come show some support and join the raid!
Meet: (link1)
Target: (link2)
Raid Call: """)
await asyncio.sleep(5)

只需要正确缩进:

async def raid(ctx):
    while True:
        await ctx.send("""@Raider come show some support and join the raid!
        Meet: (link1)
        Target: (link2)
        Raid Call: """)
        await asyncio.sleep(5)

在声明函数def raid(ctx):后,下面的块需要缩进。然后对于条件while True: 它的块也需要缩进。

如果您想学习 Python,我会推荐这门课程,它免费且非常有趣:

https://www.codecademy.com/learn/learn-python

【讨论】:

  • 以后一定要回答相关问题。这很可能很快就会关闭。如果你真的想帮助 OP,即使它的问题很接近,写评论。
  • 仍然出现错误。
  • 同样的错误?
  • 是的,同样的错误。
  • 我已经更新了答案,再试一次。如果出现错误,请记下行号
猜你喜欢
  • 2020-01-29
  • 2018-03-20
  • 2020-08-29
  • 1970-01-01
  • 2021-11-04
  • 2020-12-03
  • 2021-07-23
  • 2021-12-17
  • 2021-10-02
相关资源
最近更新 更多