-3
import host
Noms = "Name"

def init():
    host.registerHandler('ChatReceivedExtended', onTalk) # extended to distinguish between local chat and whispers

def deinit():
    host.unregisterHandler('ChatReceivedExtended', onTalk)

def onTalk(bnet, user, message, isWhisper, payload):
    if isWhisper and user.getName() == Noms:
        bnet.queueChatCommand("/me " + message)
        bnet.queueChatCommand("/f m " + message)

当我尝试运行它给我的脚本时"TypeError: OneTalk() takes exactly 5 arguments (4 given)"。但是当我将用户名添加到第 11 行时,它给了我"TypeError: OneTalk() takes exactly 5 arguments (6 given)'.

def onTalk(bnet, user, message, isWhisper, payload):

def onTalk(bnet, user, message, isWhisper, payload, username):
4

2 回答 2

1

仅基于在线 示例,它看起来像一个带有 4 个参数的方法作为处理程序,而不是您尝试的 5 或 6 个。

尝试:

def onTalk(bnet, user, message, isWhisper):
    if isWhisper and user.getName() == Noms:
        bnet.queueChatCommand("/me " + message)
        bnet.queueChatCommand("/f m " + message)

ps 如果你包含完整的回溯,它会有所帮助,并为你的执行环境提供一些上下文(例如“我正在为 pychop和 .... 编写插件”

于 2012-05-24T09:28:23.653 回答
0

按照以下建议进行更改onTalk,您将看到实际调用方式:

def onTalk( *args, **kwargs):
    print args
    print kwargs

比你可以调整参数的数量。

于 2012-05-24T09:33:26.237 回答