【发布时间】:2023-04-08 11:02:01
【问题描述】:
大家好,我正在使用 python twisted 构建一个 irc 机器人,一切都已构建,但机器人不会像我想要的那样响应命令。例如,如果我想在 irc 频道上调用一个机器人命令,我希望能够像这样调用它 $time 并让机器人回复它是什么时间,我可以让它像这样工作 -> crazybot $时间,它会打印时间,但我不想每次都输入名称...如何让机器人在不先调用名称的情况下运行命令? 这是更新->一切都连接 .......
def privmsg(self, user, channel, msg):
user = user.split('!', 1)[0]
if not msg.startswith('#'): # not a trigger command
return # do nothing
command, sep, rest = msg.lstrip('#').partition(' ')
func = getattr(self, 'command_' + command, None)
def command_time(self, *args):
return time.asctime()
.... 当我输入 !time 时没有错误也没有输出..
【问题讨论】:
-
您是否开始使用现有项目?还是你从头开始写的?
-
sscce.org 否则你不会得到有用的答案。
标签: python command twisted irc bots