Resolved issue #5688

pull/6389/head
Christiaan Blom 2017-03-03 23:15:03 +01:00
parent 0ea81c1269
commit b038a1650e
1 changed files with 10 additions and 7 deletions

View File

@ -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()