Message bus AttributeError

I created a simple notification skill following the guidelines here. Below is my source code:

from mycroft import MycroftSkill

class WakeWordDetector(MycroftSkill):
    def __init__(self):
        MycroftSkill.__init__(self)
        self.add_event('recognizer_loop:wakeword', self.handle_recognizer_wakeword)

    def handle_recognizer_wakeword(self):
        self.log.info('Wake word detected!')

def create_skill():
    return WakeWordDetector()

When I load this skill, the error below is produced.

Traceback (most recent call last):
File “/home/pi/Project/mycroft-core/mycroft/skills/skill_loader.py”, line 292, in _create_skill_instance
self.instance = skill_module.create_skill()
File “/opt/mycroft/skills/wake-word-detector-skill/init.py”, line 62, in create_skill
return WakeWordDetector()
File “/opt/mycroft/skills/wake-word-detector-skill/init.py”, line 8, in init
self.add_event(‘recognizer_loop:wakeword’, self.handle_recognizer_wakeword)
File “/home/pi/Project/mycroft-core/mycroft/skills/mycroft_skill/mycroft_skill.py”, line 946, in add_event
return self.events.add(name, wrapper, once)
File “/home/pi/Project/mycroft-core/mycroft/skills/mycroft_skill/event_container.py”, line 150, in add
self.bus.on(name, handler)
AttributeError: ‘NoneType’ object has no attribute ‘on’

It seems like it is having difficulty resolveing self.bus.

Does anyone know what the issue is? Thanks in advance!

Hey there,

I’d suggest moving the event handler registration to the initialize() method which is called after the Skill class is fully constructed. There’s some detail on the difference here:

Your handler will also receive a message object when it’s called so you need to add at least an optional argument to your handler signature, eg:

class WakeWordDetector(MycroftSkill):
    def __init__(self):
        MycroftSkill.__init__(self)

    def initialize(self):
        self.add_event('recognizer_loop:wakeword', self.handle_recognizer_wakeword)

    def handle_recognizer_wakeword(self, message):
        self.log.info('Wake word detected!')

def create_skill():
    return WakeWordDetector()

That should then log your message when the wake word is detected.

1 Like

Thank you so much for the help! Forgot that during __init__ the message bus isn’t available yet.

1 Like