带参数
的计时器对象(python)
如何使用计时器对象在ѭ1中的ѭ0之间传递参数?
def onrepeat(self,user, arg):
args = arg.split()
messagearg = args[0]
colorarg = args[1]
if colorarg == \"black\":
color = \"&0\"
if colorarg == \"dark blue\" or \"darkblue\":
color = \"&1\"
if colorarg == \"dark green\" or \"darkgreen\":
color = \"&2\"
if colorarg == \"dark teal\" or \"darkteal\":
color = \"&3\"
if colorarg == \"dark red\" or \"darkred\":
color = \"&4\"
if colorarg == \"purple\":
color = \"&5\"
if colorarg == \"gold\":
color = \"&6\"
if colorarg == \"gray\":
color = \"&7\"
if colorarg == \"dark gray\" or \"darkgrey\" or \"dark grey\" or \"darkgrey\":
color = \"&8\"
if colorarg == \"blue\":
color = \"&9\"
if colorarg == \"bright green\" or \"brightgreen\":
color = \"&a\"
if colorarg == \"teal\":
color = \"&b\"
if colorarg == \"red\":
color = \"&c\"
if colorarg == \"pink\":
color = \"&d\"
if colorarg == \"yellow\":
color = \"&e\"
if colorarg == \"white\":
color = \"&f\"
if colorarg == \"\":
color = \"&f\"
self.timerobj = Timer(3.0, self.repeat2)
self.timerobj.start()
def repeat2(self,messagearg,color):
self.bot.sendMessage(color + messagearg)
这会给我一个错误,说:
repeat2 needs 3 arguments while only 2 are given.
为了解决这个问题,我改变了
self.timerobj = Timer(3.0, self.repeat2)
至
self.timerobj = Timer(3.0, self.repeat2(messagearg,color))
但这也不起作用!
没有找到相关结果
已邀请:
1 个回复
谦响局豢报
请注意,它接受
和
。因此,只需提及它们即可将args发送到Timer函数。尝试这个: