-
-
Notifications
You must be signed in to change notification settings - Fork 37.5k
Upgrade discord.py to v1.0.1 #23523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Upgrade discord.py to v1.0.1 #23523
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,30 +39,53 @@ async def async_send_message(self, message, **kwargs): | |
|
|
||
| discord.VoiceClient.warn_nacl = False | ||
| discord_bot = discord.Client(loop=self.hass.loop) | ||
| images = None | ||
|
|
||
| if ATTR_TARGET not in kwargs: | ||
| _LOGGER.error("No target specified") | ||
| return None | ||
|
|
||
| if ATTR_DATA in kwargs: | ||
| data = kwargs.get(ATTR_DATA) | ||
|
|
||
| if ATTR_IMAGES in data: | ||
| import os.path | ||
| images = list() | ||
|
|
||
| for image in data.get(ATTR_IMAGES): | ||
| if os.path.isfile(image): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This does I/O and we're in a coroutine. That combo is not allowed. Use |
||
| images.append(image) | ||
| else: | ||
| _LOGGER.warning("Image not found: %s", image) | ||
|
|
||
| # pylint: disable=unused-variable | ||
| @discord_bot.event | ||
| async def on_ready(): | ||
| """Send the messages when the bot is ready.""" | ||
| try: | ||
| data = kwargs.get(ATTR_DATA) | ||
| images = None | ||
| if data: | ||
| images = data.get(ATTR_IMAGES) | ||
| for channelid in kwargs[ATTR_TARGET]: | ||
| channel = discord.Object(id=channelid) | ||
| await discord_bot.send_message(channel, message) | ||
| channelid = int(channelid) | ||
| channel = discord_bot.get_channel(channelid) | ||
|
|
||
| if channel is None: | ||
| _LOGGER.warning( | ||
| "Channel not found for id: %s", | ||
| channelid) | ||
| continue | ||
|
|
||
| # Must create new instances of File for each channel. | ||
| files = None | ||
| if images: | ||
| for anum, f_name in enumerate(images): | ||
| await discord_bot.send_file(channel, f_name) | ||
| files = list() | ||
| for image in images: | ||
| files.append(discord.File(image)) | ||
|
|
||
| await channel.send(message, files=files) | ||
| except (discord.errors.HTTPException, | ||
| discord.errors.NotFound) as error: | ||
| _LOGGER.warning("Communication error: %s", error) | ||
| await discord_bot.logout() | ||
| await discord_bot.close() | ||
|
|
||
| await discord_bot.start(self.token) | ||
| # Using reconnect=False prevents multiple ready events to be fired. | ||
| await discord_bot.start(self.token, reconnect=False) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This appears to have caused an unintended breaking change. If
datais not in the service call it throws aNoneTypeerror here. At minimum you must havedata:{}now in order for the service call to be successful. Reported in issue #23948There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I saw that only after I updated do 0.93, and was waiting for the weekend to fix it