不久前開始編碼,大約一個月左右。我目前編碼不和諧殭屍,一切工作正常,直到我嘗試添加新命令之後運行機器人時,此錯誤消息:IndentationError:意外的未加註
Traceback (most recent call last):
File "C:\Users\Jeriel\Desktop\JerryBot\run.py", line 162, in main
from musicbot import MusicBot
File "C:\Users\Jeriel\Desktop\JerryBot\musicbot\__init__.py", line 1, in <modu
le>
from .bot import MusicBot
File "C:\Users\Jeriel\Desktop\JerryBot\music\bot.py", line 2094
if __name__ == "__main__":
^
IndentationError: unexpected unindent
它開始我加入這之後我檢查每一行之前,我無法找到一個單一的任何地方:
async def kick(message,*args):
"""Kicks the specified user from the server"""
if len(message.mentions) < 1:
return False
if message.channel.is_private:
msg = await client.send_message(message.channel,'Users cannot be kicked/banned from private channels.')
asyncio.ensure_future(message_timeout(msg, 40))
return
if not message.channel.permissions_for(message.server.get_member(client.user.id)).kick_members:
msg = await client.send_message(message.channel, message.author.mention + ', I do not have permission to kick users.')
asyncio.ensure_future(message_timeout(msg, 40))
return
members = []
if not message.channel.is_private and message.channel.permissions_for(message.author).kick_members:
for member in message.mentions:
if member != message.author:
try:
await client.kick(member)
members.append(member.name)
except:
pass
else:
msg = await client.send_message(message.channel, message.author.mention + ', You should not kick yourself from a channel, use the leave button instead.')
asyncio.ensure_future(message_timeout(msg, 40))
else:
msg = await client.send_message(message.channel, message.author.mention + ', I do not have permission to kick users, or this is a private message channel.')
asyncio.ensure_future(message_timeout(msg, 40))
msg = await client.send_message(message.channel,'Successfully kicked user(s): `{}`'.format('`, `'.join(members)))
asyncio.ensure_future(message_timeout(msg, 60))
@register('ban','@<mention users>',owner=True)
async def ban(message,*args):
"""Bans the specified user from the server"""
if len(message.mentions) < 1:
return False
if message.channel.is_private:
msg = await client.send_message(message.channel,'Users cannot be kicked/banned from private channels.')
asyncio.ensure_future(message_timeout(msg, 40))
return
if not message.channel.permissions_for(message.server.get_member(client.user.id)).ban_members:
msg = await client.send_message(message.channel, message.author.mention + ', I do not have permission to ban users.')
asyncio.ensure_future(message_timeout(msg, 40))
return
members = []
if message.channel.permissions_for(message.author).ban_members:
for member in message.mentions:
if member != message.author:
try:
await client.ban(member)
members.append(member.name)
except:
pass
else:
msg = await client.send_message(message.channel, message.author.mention + ', You should not ban yourself from a channel, use the leave button instead.')
asyncio.ensure_future(message_timeout(msg, 40))
else:
msg = await client.send_message(message.channel, message.author.mention + ', I do not have permission to ban users, or this is a private message channel.')
asyncio.ensure_future(message_timeout(msg, 40))
msg = await client.send_message(message.channel,'Successfully banned user(s): `{}`'.format('`, `'.join(members)))
asyncio.ensure_future(message_timeout(msg, 30))
@register('bans',alias='bannedusers')
@register('bannedusers')
if __name__ == "__main__":
bot = JerryBot()
bot.run("---")
錯誤消息指向'if __name__ ==「__main __」:'。爲什麼該行相對於代碼的其餘部分是縮進的? – Blorgbeard
您是否複製並粘貼了您的代碼,或將其輸入到自己的代碼中?如果您複製並粘貼它,可能是由於您在某些地方使用製表符縮進以及在其他位置使用縮進縮進的問題。這樣做總是搞笑的東西... – colelemonz
@Blorgbeard我認爲OP希望使用'if __name__ =='__main __「:'塊作爲主要功能,如果是的話那麼它必須是非縮進 – colelemonz