From 2df3c85ba65e12564a90947592b7994ce00ac4f1 Mon Sep 17 00:00:00 2001 From: kezziny Date: Wed, 12 Jan 2022 14:37:22 +0100 Subject: [PATCH] Fix discord component using userid as target (#63972) --- homeassistant/components/discord/notify.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/discord/notify.py b/homeassistant/components/discord/notify.py index c3f7de94af0..e8b084a01ab 100644 --- a/homeassistant/components/discord/notify.py +++ b/homeassistant/components/discord/notify.py @@ -94,12 +94,13 @@ class DiscordNotificationService(BaseNotificationService): for channelid in kwargs[ATTR_TARGET]: channelid = int(channelid) try: - channel = await discord_bot.fetch_channel( - channelid - ) or await discord_bot.fetch_user(channelid) + channel = await discord_bot.fetch_channel(channelid) except discord.NotFound: - _LOGGER.warning("Channel not found for ID: %s", channelid) - continue + try: + channel = await discord_bot.fetch_user(channelid) + except discord.NotFound: + _LOGGER.warning("Channel not found for ID: %s", channelid) + continue # Must create new instances of File for each channel. files = [discord.File(image) for image in images] if images else None await channel.send(message, files=files, embed=embed)