From b038a1650e96773ecea7e9378b8e445f3cec676a Mon Sep 17 00:00:00 2001 From: Christiaan Blom Date: Fri, 3 Mar 2017 23:15:03 +0100 Subject: [PATCH] Resolved issue #5688 --- homeassistant/components/notify/discord.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/notify/discord.py b/homeassistant/components/notify/discord.py index e6c4b3bad96..fa8aa72cef3 100644 --- a/homeassistant/components/notify/discord.py +++ b/homeassistant/components/notify/discord.py @@ -35,18 +35,21 @@ class DiscordNotificationService(BaseNotificationService): """Initialize the service.""" self.token = token self.hass = hass + self.loggedin = 0 @asyncio.coroutine def async_send_message(self, message, **kwargs): """Login to Discord, send message to channel(s) and log out.""" import discord discord_bot = discord.Client(loop=self.hass.loop) + + @discord_bot.event + @asyncio.coroutine + def on_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.login(self.token) + yield from discord_bot.start(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()