python - 没有外部字符或必要的缩进,但仍然出现未缩进的错误。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 有一篇与此类似的帖子,尽管我确实尝试过,但它并没有解决问题。请不要将此标记为重复,因为它不是一个。
解决方案
正如错误告诉你的那样,你没有正确缩进代码
@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
语句和channel
where 处于不同的缩进级别。这会引发错误,因为通道不匹配任何其他缩进级别。
推荐阅读
- pandas - 如何导入带有表情符号的csv
- spring-security - Spring Security 授权服务器实验性 - Maven 存储库缺少 0.2.0
- java - 用java在oracle中获取json
- java - Android Text to Speech相对于时间的控制率
- angular - Angular和localStorage如何获得一个唯一的密钥
- flutter - 从 SingleChildScrollView 垂直滚动 PageView
- powerapps - 使用 PowerApps ForAll + Patch 更新 Excel 表的所有行
- r - 如何使用 dbplyr 和 dplyr 构建用于查询数据库的包装函数,使查询有所不同
- reactjs - 当整个应用程序在 React js 中崩溃时如何隐藏错误信息
- azure - 使用 Azure Function 在 CosmosDB 表中读取 changefeed