python - 使用 python IndentationError 编码的 Discord bot:unindent 不匹配任何外部缩进级别
问题描述
File "main.py", line 16
await message.channel.send ('Sample text')
^
IndentationError: unindent 不匹配任何外部缩进级别
我试图制作一个不和谐的机器人,这又来了!
完整代码
import discord
import os
#discord client
client = discord.Client()
#event
@client.event
async def on_ready():
print('Logged in as {0.user}'.format(client))
#event register
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('$vrise'):
await message.channel.send ('Text')
client.run(os.getenv('TOKEN'))
解决方案
现在更新了您发布的代码,感谢您更新问题!
您的代码已取消缩进。将其更改为:
import discord
import os
# discord client
client = discord.Client()
# event
@client.event
async def on_ready():
print('Logged in as {0.user}'.format(client))
# event register
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('$vrise'): # This was one indent to much
await message.channel.send('Text')
client.run(os.getenv('TOKEN'))
请注意 if 语句以及它们的缩进如何与其范围相匹配。
推荐阅读
- stored-procedures - DB2 LUW - 在存储过程中获取错误行
- powershell - 从 60 天以前的路径中删除文件失败
- javascript - 从 Javascript 异步函数访问变量以进行排序
- python - Jupyter 和 %matplotlib 内联丢失轴
- reactjs - 测试自定义钩子的返回值
- kubernetes - 在 Airflow Cloud Composer 中从 Kubernetes Pod Operator 推送 Docker 镜像
- payment - Adyen,无需付款即可为信用卡创建令牌
- javascript - Typedoc 错误:尝试设置未声明的选项(模式)
- http-live-streaming - 使用 Stream/RAF Tester 调试 Roku 技巧模式
- c++ - 递归获取提升属性树中所有值的完整关键路径