[英]How to initialize Python Slackbot module?
我是 Slack 机器人的新手(熟悉 Discord.py)。 我正在使用 Slackbot 包 ( https://github.com/lins05/slackbot ) 来创建我的 Python slack 机器人。
跟着他们的页面上的例子,安装使用包pip install slackbot
,又到了安装的路径,创造了一个slackbot_settings.py
(与他们提到指定标签)和run.py
在主目录和mybot.py
(例如带命令他们显示在他们的页面上进行测试),但我无法初始化机器人。 我尝试使用 python run.py
运行机器人,但出现以下错误:
Traceback (most recent call last):
File "run.py", line 23, in
main()
File "run.py", line 20, in main
bot.run()
File "/Users/xxx/anaconda3/lib/python3.5/site-packages/slackbot/bot.py", line 32, in run
self._plugins.init_plugins()
File "/Users/xxx/anaconda3/lib/python3.5/site-packages/slackbot/manager.py", line 31, in init_plugins
self._load_plugins(plugin)
File "/Users/xxx/anaconda3/lib/python3.5/site-packages/slackbot/manager.py", line 47, in _load_plugins
path_name = importlib_find(plugin)
File "/Users/xxx/anaconda3/lib/python3.5/importlib/util.py", line 89, in find_spec
return _find_spec(fullname, parent.path)
AttributeError: module 'mybot' has no attribute 'path'
mybot.py
有以下几行:
from slackbot.bot import respond_to
from slackbot.bot import listen_to
import re
@respond_to('hi', re.IGNORECASE)
def hi(message):
message.reply('I can understand hi or HI!')
# react with thumb up emoji
message.react('+1')
@respond_to('I love you')
def love(message):
message.reply('I love you too!')
@listen_to('Can someone help me?')
def help(message):
# Message is replied to the sender (prefixed with @user)
message.reply('Yes, I can!')
# Message is sent on the channel
message.send('I can help everybody!')
# Start a thread on the original message
message.reply("Here's a threaded reply", in_thread=True)
我哪里错了? 我试过问开发商,但没有得到答复。
机器人显然找不到您的 mybot 插件。 假设mybot.py
与mybot.py
位于同一文件夹中, run.py
PLUGINS
的条目更改为'mybot'
。 那么它应该工作。
slackbot_settings.py
完整示例:
DEFAULT_REPLY = "Sorry but I didn't understand you"
PLUGINS = [
'mybot'
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.