在 telepot 上弄脏我的手并面临问题
Getting my hand dirty on telepot and facing issues
我从各处挑选了一些,几个月前它运行良好,但是最近当我返回我的项目时,代码给出了一个错误,我什至不是 [=16 的初学者=] 边走边学。
Traceback (most recent call last):
File "/home/soumyadeep/Downloads/telepot.py", line 2, in
<module>
import telepot, time
File "/home/soumyadeep/Downloads/telepot.py", line 38, in
<module>
bot = telepot.Bot('Token')
AttributeError: partially initialized module 'telepot' has no
attribute 'Bot' (most likely due to a circular import)
是错误代码是
#!/usr/bin/python
import telepot, time
def handle(msg):
content_type, chat_type, chat_id = telepot.glance(msg)
if (content_type == 'text'):
command = msg['text']
print ('Got command: %s' % command)
if '/hello' in command:
bot.sendMessage(chat_id, "Hello, do you have any commands for today?")
if '/iamsudo' in command:
bot.sendMessage(chat_id, "Hello, Soumyadeep. How can I assist you today?")
if '/iamroot' in command:
bot.sendMessage(chat_id, "Hello, Soumyadeep. How can I assist you today?")
if '/NodeRed' in command:
bot.sendMessage(chat_id, "Let me help you with that. Initiating in some time.")
if '/name' in command:
bot.sendMessage(chat_id, "You can call me Ether.")
if '/master' in command:
bot.sendMessage(chat_id, "I am a roughly done bot from Soumyadeep Chatterjee.")
if '/mother' in command:
bot.sendMessage(chat_id, "Requesting initiation.")
if '/start' in command:
bot.sendMessage(chat_id, "Hello. What can I assist you with?")
if '/delta' in command:
bot.sendMessage(chat_id, "Initiating delta sequence. Awaiting authorization from home server.")
if '/goodnight' in command:
bot.sendMessage(chat_id, "Initiating do no disturb throughout the network. ")
if '/goodmorning' in command:
bot.sendMessage(chat_id, "Good morning, love. Refreshing the network.")
if '/goodbye' in command:
bot.sendMessage(chat_id, "Have a good day, love. Starting a lockdown on the home server.")
# Creates a bot using the token provided by BotFather
bot = telepot.Bot('Token')
# Add the handle function to be called every new received
message
bot.message_loop(handle)
# Wait for new messages
while 1:
time.sleep(20)
错误消息准确地告诉您您做了什么。您有一个名为 telepot.py
的文件正在执行 import telepot
。你不能那样做。那就是循环导入。如果您有一个名为 telepot
的模块,那么您必须将程序的文件名更改为其他名称。
顺便说一句,你的一长串 if
语句应该是 if
/elif
/elif
/elif
... 如果消息总是从那个开始,那么将所有这些消息放入字典并根据第一个词进行一次查找会更聪明。
我从各处挑选了一些,几个月前它运行良好,但是最近当我返回我的项目时,代码给出了一个错误,我什至不是 [=16 的初学者=] 边走边学。
Traceback (most recent call last):
File "/home/soumyadeep/Downloads/telepot.py", line 2, in
<module>
import telepot, time
File "/home/soumyadeep/Downloads/telepot.py", line 38, in
<module>
bot = telepot.Bot('Token')
AttributeError: partially initialized module 'telepot' has no
attribute 'Bot' (most likely due to a circular import)
是错误代码是
#!/usr/bin/python
import telepot, time
def handle(msg):
content_type, chat_type, chat_id = telepot.glance(msg)
if (content_type == 'text'):
command = msg['text']
print ('Got command: %s' % command)
if '/hello' in command:
bot.sendMessage(chat_id, "Hello, do you have any commands for today?")
if '/iamsudo' in command:
bot.sendMessage(chat_id, "Hello, Soumyadeep. How can I assist you today?")
if '/iamroot' in command:
bot.sendMessage(chat_id, "Hello, Soumyadeep. How can I assist you today?")
if '/NodeRed' in command:
bot.sendMessage(chat_id, "Let me help you with that. Initiating in some time.")
if '/name' in command:
bot.sendMessage(chat_id, "You can call me Ether.")
if '/master' in command:
bot.sendMessage(chat_id, "I am a roughly done bot from Soumyadeep Chatterjee.")
if '/mother' in command:
bot.sendMessage(chat_id, "Requesting initiation.")
if '/start' in command:
bot.sendMessage(chat_id, "Hello. What can I assist you with?")
if '/delta' in command:
bot.sendMessage(chat_id, "Initiating delta sequence. Awaiting authorization from home server.")
if '/goodnight' in command:
bot.sendMessage(chat_id, "Initiating do no disturb throughout the network. ")
if '/goodmorning' in command:
bot.sendMessage(chat_id, "Good morning, love. Refreshing the network.")
if '/goodbye' in command:
bot.sendMessage(chat_id, "Have a good day, love. Starting a lockdown on the home server.")
# Creates a bot using the token provided by BotFather
bot = telepot.Bot('Token')
# Add the handle function to be called every new received
message
bot.message_loop(handle)
# Wait for new messages
while 1:
time.sleep(20)
错误消息准确地告诉您您做了什么。您有一个名为 telepot.py
的文件正在执行 import telepot
。你不能那样做。那就是循环导入。如果您有一个名为 telepot
的模块,那么您必须将程序的文件名更改为其他名称。
顺便说一句,你的一长串 if
语句应该是 if
/elif
/elif
/elif
... 如果消息总是从那个开始,那么将所有这些消息放入字典并根据第一个词进行一次查找会更聪明。