首页 > 解决方案 > 没有外部字符或必要的缩进,但仍然出现未缩进的错误。Repl.it Python Discord Bot 特殊命令

问题描述

我正在为我的不和谐机器人制作 Repl.it 代码。有一个特定的命令不断给我一个错误。该命令的想法是,如果他们要求管理员或版主,它将把一个人转移到一个“监狱”服务器,因为这些角色有一个特定的应用程序通道。它不断给我“unindent 与任何外部缩进级别不匹配”错误,似乎无论我做什么它都会继续给出相同的错误。

@bot.command()
async def give(ctx, *, arg):
    if ctx.invoked_subcommand is None:
      await bot.say('youre going to *channel name*')~
  channel = bot.get_channel(*channel ID*)
  member = bot.get_member(0.subcommand_passed)
    await member.move_to(*channel name*)

错误由我已经检查过的“~”标记,那里没有空格或任何类型的字符。我在网上看了,检查了 Python 指南,都无济于事。谁能帮我这个?感谢所有帮助。

发表声明:@Deleted-User 有一篇与此类似的帖子,尽管我确实尝试过,但它并没有解决问题。请不要将此标记为重复,因为它不是一个。

标签: pythondiscordbots

解决方案


正如错误告诉你的那样,你没有正确缩进代码

@bot.command()
async def give(ctx, *, arg):
   if ctx.invoked_subcommand is None:
       await bot.say('youre going to *channel name*')~
   channel = bot.get_channel(*channel ID*)
   member = bot.get_member(0.subcommand_passed)
   await member.move_to(*channel name*)

在您的代码中,if语句和channelwhere 处于不同的缩进级别。这会引发错误,因为通道不匹配任何其他缩进级别。


推荐阅读