diff --git a/homeassistant/components/notify/discord.py b/homeassistant/components/notify/discord.py index e6c4b3bad96cd9..189aa0d02bbed4 100644 --- a/homeassistant/components/notify/discord.py +++ b/homeassistant/components/notify/discord.py @@ -42,11 +42,14 @@ def async_send_message(self, message, **kwargs): import discord discord_bot = discord.Client(loop=self.hass.loop) - yield from discord_bot.login(self.token) - - for channelid in kwargs[ATTR_TARGET]: - channel = discord.Object(id=channelid) - yield from discord_bot.send_message(channel, message) - - yield from discord_bot.logout() - yield from discord_bot.close() + @discord_bot.event + @asyncio.coroutine + def on_ready(): # pylint: disable=unused-variable + """Send the messages when the bot is ready.""" + for channelid in kwargs[ATTR_TARGET]: + channel = discord.Object(id=channelid) + yield from discord_bot.send_message(channel, message) + yield from discord_bot.logout() + yield from discord_bot.close() + + yield from discord_bot.start(self.token)