youfou / wxpy

微信机器人 / 可能是最优雅的微信个人号 API ✨✨
http://wxpy.readthedocs.io
MIT License
13.99k stars 2.38k forks source link

请问函数在main外面为啥不能注册成功? #60

Closed vicliu6 closed 7 years ago

vicliu6 commented 7 years ago

把函数放到main里面就可以运行 但是要怎样可以放到外面呢? 不好意思,谢谢

from wxpy import *

def print_others(msg):

print(msg)
return msg.text

if name == "main" :

bot = Bot()
bot.register( print_others )
embed( shell= 'ipython' )
vicliu6 commented 7 years ago

自问自答一下,这样就行了

from wxpy import *

bot = Bot()

@bot.register() def print_others(msg):

print(msg)
return msg.text

if name == "main" :

embed( shell= 'ipython' )