【发布时间】:2022-01-26 18:21:23
【问题描述】:
我对 python 很陌生,我正在尝试制作一个不和谐的机器人,只要它找到与食物相关的单词就会发送消息。这是我想出的,它在第 147 行给了我一个缩进错误。为什么会这样,我该怎么办?
编辑:我已将代码从 repl.it 复制粘贴到此处
### Alert bot to food words and reply with a message from a list ###
@bot.event
async def on_message(message):
if 'spag' in message.content:
await ctx.channel.send(random.choice(spaghet))
if 'meat' in message.content:
await ctx.channel.send(random.choice(meat))
if 'dinner' in message.content:
await ctx.channel.send(random.choice(dinner_words))
if 'lunch' in message.content:
await ctx.channel.send(random.choice(lunch_words))
if 'breakfast' in message.content:
await ctx.channel.send(random.choice(breakfast_words))
if any (word in message.content for word in omit):
return
await bot.process_commands(message)
感谢您的帮助
【问题讨论】:
-
您可能正在混合制表符和空格。错误的确切文本是什么?
-
@MattDMo "IndentationError: unindent 不匹配任何外部缩进级别。"不过,我没有使用任何空格。
-
请edit您的问题并将您的代码复制到其中,使用代码格式化工具(
{})正确格式化。请不要更改任何内容,只需复制并粘贴即可。 -
哦,将其复制粘贴到此处使我的错误可见。我看到我做了什么,我已经修复了它。谢谢@MattDMo
标签: python discord discord.py