首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何初始化Python Slackbot模块?

如何初始化Python Slackbot模块?
EN

Stack Overflow用户
提问于 2019-06-28 02:55:14
回答 1查看 229关注 0票数 2

我是Slack机器人的新手(熟悉Discord.py)。我正在使用Slackbot包(https://github.com/lins05/slackbot)来创建我的Python slack机器人。

遵循他们页面上的示例,使用pip install slackbot安装软件包,转到安装路径,在主目录中创建一个slackbot_settings.py (带有他们提到的指定标签)和run.py,以及mybot.py (带有他们在页面上显示的用于测试的示例命令),但我无法初始化机器人。我尝试使用python run.py运行机器人,但得到以下错误:

代码语言:javascript
复制
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有以下几行:

代码语言:javascript
复制
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)

我哪里错了?我试着询问开发人员,但没有得到任何答复。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-06-28 20:18:32

机器人显然找不到你的mybot插件。假设mybot.pyrun.py在同一个文件夹中,将PLUGINS中的条目更改为'mybot'。那么它应该是有效的。

slackbot_settings.py的完整示例

代码语言:javascript
复制
DEFAULT_REPLY = "Sorry but I didn't understand you"

PLUGINS = [    
    'mybot' 
]
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56797185

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档