Replace discord.py with nextcord (#66540)
* Replace discord.py with nextcord * Typing tweak * Another pip check decrease :)
This commit is contained in:
parent
23a22d1860
commit
cb03db8df4
4 changed files with 19 additions and 16 deletions
|
@ -2,7 +2,7 @@
|
|||
"domain": "discord",
|
||||
"name": "Discord",
|
||||
"documentation": "https://www.home-assistant.io/integrations/discord",
|
||||
"requirements": ["discord.py==1.7.3"],
|
||||
"requirements": ["nextcord==2.0.0a8"],
|
||||
"codeowners": [],
|
||||
"iot_class": "cloud_push",
|
||||
"loggers": ["discord"]
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
"""Discord platform for notify component."""
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import os.path
|
||||
|
||||
import discord
|
||||
import nextcord
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.notify import (
|
||||
|
@ -48,8 +50,8 @@ class DiscordNotificationService(BaseNotificationService):
|
|||
|
||||
async def async_send_message(self, message, **kwargs):
|
||||
"""Login to Discord, send message to channel(s) and log out."""
|
||||
discord.VoiceClient.warn_nacl = False
|
||||
discord_bot = discord.Client()
|
||||
nextcord.VoiceClient.warn_nacl = False
|
||||
discord_bot = nextcord.Client()
|
||||
images = None
|
||||
embedding = None
|
||||
|
||||
|
@ -59,13 +61,13 @@ class DiscordNotificationService(BaseNotificationService):
|
|||
|
||||
data = kwargs.get(ATTR_DATA) or {}
|
||||
|
||||
embed = None
|
||||
embeds: list[nextcord.Embed] = []
|
||||
if ATTR_EMBED in data:
|
||||
embedding = data[ATTR_EMBED]
|
||||
fields = embedding.get(ATTR_EMBED_FIELDS) or []
|
||||
|
||||
if embedding:
|
||||
embed = discord.Embed(**embedding)
|
||||
embed = nextcord.Embed(**embedding)
|
||||
for field in fields:
|
||||
embed.add_field(**field)
|
||||
if ATTR_EMBED_FOOTER in embedding:
|
||||
|
@ -74,11 +76,12 @@ class DiscordNotificationService(BaseNotificationService):
|
|||
embed.set_author(**embedding[ATTR_EMBED_AUTHOR])
|
||||
if ATTR_EMBED_THUMBNAIL in embedding:
|
||||
embed.set_thumbnail(**embedding[ATTR_EMBED_THUMBNAIL])
|
||||
embeds.append(embed)
|
||||
|
||||
if ATTR_IMAGES in data:
|
||||
images = []
|
||||
|
||||
for image in data.get(ATTR_IMAGES):
|
||||
for image in data.get(ATTR_IMAGES, []):
|
||||
image_exists = await self.hass.async_add_executor_job(
|
||||
self.file_exists, image
|
||||
)
|
||||
|
@ -95,15 +98,15 @@ class DiscordNotificationService(BaseNotificationService):
|
|||
channelid = int(channelid)
|
||||
try:
|
||||
channel = await discord_bot.fetch_channel(channelid)
|
||||
except discord.NotFound:
|
||||
except nextcord.NotFound:
|
||||
try:
|
||||
channel = await discord_bot.fetch_user(channelid)
|
||||
except discord.NotFound:
|
||||
except nextcord.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)
|
||||
except (discord.HTTPException, discord.NotFound) as error:
|
||||
files = [nextcord.File(image) for image in images] if images else []
|
||||
await channel.send(message, files=files, embeds=embeds)
|
||||
except (nextcord.HTTPException, nextcord.NotFound) as error:
|
||||
_LOGGER.warning("Communication error: %s", error)
|
||||
await discord_bot.close()
|
||||
|
|
|
@ -565,9 +565,6 @@ directv==0.4.0
|
|||
# homeassistant.components.discogs
|
||||
discogs_client==2.3.0
|
||||
|
||||
# homeassistant.components.discord
|
||||
discord.py==1.7.3
|
||||
|
||||
# homeassistant.components.steamist
|
||||
discovery30303==0.2.1
|
||||
|
||||
|
@ -1099,6 +1096,9 @@ nexia==0.9.13
|
|||
# homeassistant.components.nextcloud
|
||||
nextcloudmonitor==1.1.0
|
||||
|
||||
# homeassistant.components.discord
|
||||
nextcord==2.0.0a8
|
||||
|
||||
# homeassistant.components.niko_home_control
|
||||
niko-home-control==0.2.1
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ PIP_CACHE=$1
|
|||
|
||||
# Number of existing dependency conflicts
|
||||
# Update if a PR resolve one!
|
||||
DEPENDENCY_CONFLICTS=10
|
||||
DEPENDENCY_CONFLICTS=9
|
||||
|
||||
PIP_CHECK=$(pip check --cache-dir=$PIP_CACHE)
|
||||
LINE_COUNT=$(echo "$PIP_CHECK" | wc -l)
|
||||
|
|
Loading…
Add table
Reference in a new issue