4 Commits

Author SHA1 Message Date
30da1159e1 Fix documentation for VoiceChannel.create_party 2021-08-31 11:04:09 +06:00
8ec591e46b Add support for creating parties 2021-08-30 11:43:03 +06:00
773ad6f5bf add back the silent kwarg to message.delete (#9)
* add back the silent kwarg to message.delete

* forgot about versionadded

* shorten the if statement

* simplify raising a bit ig?

* should be versionchanged instead

Co-authored-by: Arthur <site-github@api-d.com>

* remove `Optional` from parameter and doc string

Co-authored-by: Arthur <site-github@api-d.com>
2021-08-29 10:57:07 -07:00
de0e8ef108 V2.0 changelog (#8)
* Copy in messages from Danny, verbatim

* Type whats_new

* Add my changes to the changelog

* Fix a typo
2021-08-29 10:55:49 -07:00
6 changed files with 276 additions and 3 deletions

View File

@ -45,7 +45,7 @@ import datetime
import discord.abc
from .permissions import PermissionOverwrite, Permissions
from .enums import ChannelType, StagePrivacyLevel, try_enum, VoiceRegion, VideoQualityMode
from .enums import ChannelType, StagePrivacyLevel, try_enum, VoiceRegion, VideoQualityMode, PartyType
from .mixins import Hashable
from .object import Object
from . import utils
@ -1037,6 +1037,38 @@ class VoiceChannel(VocalGuildChannel):
# the payload will always be the proper channel payload
return self.__class__(state=self._state, guild=self.guild, data=payload) # type: ignore
async def create_party(self, application_id: PartyType, max_age: int = 86400 , max_uses: int = 0):
"""|coro|
Creates a party in this voice channel.
.. versionadded:: 2.0
Parameters
----------
application_id : :class:`PartyType`
The id of the application the party belongs to. currently any of
``PartyType.youtube``, ``PartyType.poker``, ``PartyType.betrayal``, ``PartyType.fishing``, ``PartyType.chess``.
max_age : :class:`int`, optional
Duration in seconds after which the invite expires, by default 1 day.
max_uses : :class:`int`, optional
maximum number of times this invite can be used, by default unlimited.
Raises
-------
Forbidden
You do not have permissions to create a party.
HTTPException
Party creation failed.
Returns
--------
:class:`Party`
The created party.
"""
return Party(await self._state.http.create_party(self.id, application_id.value, max_age=max_age, max_uses=max_uses))
class StageChannel(VocalGuildChannel):
"""Represents a Discord guild stage channel.
@ -2038,6 +2070,76 @@ class PartialMessageable(discord.abc.Messageable, Hashable):
return PartialMessage(channel=self, id=message_id)
class Party:
"""Represents a party in a voice channel.
.. container:: operations
.. describe:: x == y
Checks if two party are equal.
.. describe:: x != y
Checks if two party are not equal.
.. describe:: hash(x)
Returns the party hash.
.. describe:: str(x)
Returns the party URL.
Attributes
-----------
code: :class:`str`
The URL fragment used for the party.
uses: :class:`int`
How many times the invite has been used.
max_uses: :class:`int`
How many times the invite can be used.
A value of ``0`` indicates that it has unlimited uses.
max_age: :class:`int`
How long before the party expires in seconds.
A value of ``0`` indicates that it doesn't expire.
temporary: :class:`bool`
Indicates that the invite grants temporary membership.
If ``True``, members who joined via this invite will be kicked upon disconnect.
created_at: :class:`datetime.datetime`
An aware UTC datetime object denoting the time the invite was created.
Note
----
Parties are still in BETA so there are some limitations.
Currently this BETA feature is only supported on web and updated PC app versions of Discord and is not supported on mobile.
First someone has to to click the blue link itself and not the join button, then everyone else can click the join button normally.
"""
__slots__ = ('code', 'uses', 'max_uses', 'max_age', 'temporary', 'created_at')
def __init__(self, data):
self.code: str = data['code']
self.uses: Optional[int] = data.get('uses')
self.max_uses: Optional[int] = data.get('max_uses')
self.max_age: Optional[int] = data.get('max_age')
self.temporary: Optional[bool] = data.get('temporary')
self.created_at: Optional[datetime.datetime] = utils.parse_time(data.get('created_at'))
# TODO: add more fields here such as guild. raw data: https://mystb.in/AdvertisersExperiencesMothers.json
def __repr__(self):
return f'<Party code={self.code}>'
def __str__(self):
return f'https://discord.gg/{self.code}'
def __hash__(self) -> int:
return hash(self.code)
def __eq__(self, other):
return isinstance(other, Party) and self.code == other.code
def _guild_channel_factory(channel_type: int):
value = try_enum(ChannelType, channel_type)

View File

@ -30,6 +30,7 @@ __all__ = (
'Enum',
'ChannelType',
'MessageType',
'PartyType',
'VoiceRegion',
'SpeakingState',
'VerificationLevel',
@ -214,6 +215,14 @@ class MessageType(Enum):
guild_invite_reminder = 22
class PartyType(Enum):
youtube = 755600276941176913
poker = 755827207812677713
betrayal = 773336526917861400
fishing = 814288819477020702
chess = 832012774040141894
class VoiceRegion(Enum):
us_west = 'us-west'
us_east = 'us-east'

View File

@ -880,6 +880,24 @@ class HTTPClient:
) -> Response[None]:
return self.request(Route('DELETE', '/channels/{channel_id}', channel_id=channel_id), reason=reason)
def create_party(
self,
channel_id: Snowflake,
application_id: Snowflake,
max_age: int,
max_uses: int,
) -> Response[channel.Party]:
payload = {
'max_age': max_age,
'max_uses': max_uses,
'target_application_id': application_id,
'target_type': 2,
'temporary': False,
'validate': None
}
return self.request(Route("POST", "/channels/{channel_id}/invites", channel_id=channel_id), json=payload)
# Thread management
def start_thread_with_message(

View File

@ -1106,7 +1106,7 @@ class Message(Hashable):
if self.type is MessageType.guild_invite_reminder:
return 'Wondering who to invite?\nStart by inviting anyone who can help you build the server!'
async def delete(self, *, delay: Optional[float] = None) -> None:
async def delete(self, *, delay: Optional[float] = None, silent: bool = False) -> None:
"""|coro|
Deletes the message.
@ -1117,12 +1117,17 @@ class Message(Hashable):
.. versionchanged:: 1.1
Added the new ``delay`` keyword-only parameter.
.. versionchanged:: 2.0
Added the new ``silent`` keyword-only parameter.
Parameters
-----------
delay: Optional[:class:`float`]
If provided, the number of seconds to wait in the background
before deleting the message. If the deletion fails then it is silently ignored.
silent: :class:`bool`
If silent is set to ``True``, the error will not be raised, it will be ignored.
This defaults to ``False``
Raises
------
@ -1144,7 +1149,11 @@ class Message(Hashable):
asyncio.create_task(delete(delay))
else:
await self._state.http.delete_message(self.channel.id, self.id)
try:
await self._state.http.delete_message(self.channel.id, self.id)
except Exception:
if not silent:
raise
@overload
async def edit(

View File

@ -155,3 +155,10 @@ class StageInstance(TypedDict):
topic: str
privacy_level: PrivacyLevel
discoverable_disabled: bool
class Party(TypedDict):
uses: int
max_uses: int
max_age: int
temporary: bool
created_at: str

View File

@ -11,6 +11,134 @@ Changelog
This page keeps a detailed human friendly rendering of what's new and changed
in specific versions.
.. _vp2p0p0:
v2.0.0
--------
This version was partly developed by Danny, and partly by the enhanced-discord.py contributors.
The library has been updated with breaking changes, and as such the major version was changed.
- Performance of the library has improved significantly (all times with 1 process and 1 AutoShardedBot):
- 735 guilds boot up time (with chunking): 57s/1.7 GiB RAM -> 42s/1.4 GiB RAM
- 27k guilds boot up time (with chunking): 477s/8 GiB RAM -> 303s/7.2 GiB RAM
- 48k guilds boot up time (without chunking): 109s -> 67s
- 106k guilds boot up time (without chunking): 3300s -> 3090s
- The entire public API of the library is now completely type hinted.
- There may still be bugs however.
- For best type hinting experience consider using Pyright.
- Almost all edit methods now return their updated counterpart rather than doing an in-place edit.
- Japanese docs were removed, as we are no longer able to keep them in sync.
Breaking Changes
~~~~~~~~~~~~~~~~~
- :meth:`Asset.replace` now only accepts keyword arguments
- ``Asset.with_`` functions now only accept positional only arguments
- :meth:`TextChannel.get_partial_message` is now pos-only
- :meth:`TextChannel.get_thread` is now pos-only
- ``permissions_for`` is now pos-only
- :attr:`GroupChannel.owner` is now Optional
- ``edit`` methods now only accept None if it actually means something (e.g. clearing it)
- ``timeout`` parameter for ``ui.View.__init__`` is now keyword only
- When an interaction has already been responded and another one is sent, :exc:`InteractionResponded`is now raised.
- Discord's API only allows a single :attr:`interaction.response`.
- Separate :func:`on_member_update` and :func:`on_presence_update`
- The new event :func:`on_presence_update` is now called when status/activity is changed.
- :func:`on_member_update` will now no longer have status/activity changes.
- afk parameter in :meth:`Client.change_presence` is removed
- The undocumented private :func:`on_socket_response` event got removed.
- Consider using the newer documented :func:`on_socket_event_type` event instead.
- Using :func:`on_socket_raw_receive` and :func:`on_socket_raw_send` are now opt-in via :attr:`enable_debug_events` toggle.
- :func:`on_socket_raw_receive` is now only dispatched after decompressing the payload.
- Persistent View dispatch mechanism now uses the ``message_id`` key if provided.
- :meth:`Message.start_thread` was renamed to :meth:`Message.create_thread`
- :meth:`TextChannel.start_thread` was renamed to :meth:`TextChannel.create_thread`
- All ``get_`` lookup functions now use positional-only parameters for the id parameter.
- Remove :meth:`TextChannel.active_threads` due to the endpoint being deprecated and slated for removal.
- Use :meth:`Guild.active_threads` instead.
- :attr:`User.avatar` now returns None if the user did not upload an avatar.
- Use :attr:`User.display_avatar` to get the avatar and fallback to the default avatar to go back to the old behaviour.
New Features
~~~~~~~~~~~~~~
- Channel types are now typed
- Member is now typed
- Client is now typed
- Permissions are now typed
- Core library errors are now typed
- Add various examples showing how to use views. There are more to come.
- :attr:`GroupChannel.owner_id` now gets the owner ID
- ``edit`` methods now don't rely on previous state
- :meth:`View.from_message` converts a Message.components to a View
- :attr:`Thread.type` to get the thread channel type
- :attr:`ButtonStyle.url` alias for :attr:`ButtonStyle.link`
- Add default style for :class:`ui.Button` constructor
- This makes it so creating a URL button is as simple as ``ui.Button(url='...', label='...')``
- :attr:`Thread.mention` to get the mention string for a thread
- :meth:`Thread.is_nsfw` to check whether the parent channel of the thread is NSFW
- Add support for fetching the original interaction response message.
- :meth:`Interaction.original_message` will retrieve it and returns an InteractionMessage
- :meth:`InteractionMessage.edit` or :meth:`Interaction.edit_original_message` will edit it
- :meth:`InteractionMessage.delete` or :meth:`Interaction.delete_original_message` will delete it
- :attr:`MessageFlags.ephemeral` to get whether a message is ephemeral
- :meth:`Client.fetch_channel` now fetches threads as well
- :class:`SelectOption` now has a __str__ that matches the client representation.
- This might change in the future to remove the description from it.
- Add a converter for :class:`discord.Thread`
- Allow ``clean_content`` converter to work stand-alone
- Add :meth:`User.banner` to get a user's banner and :meth:`User.accent_colour` to get the set banner colour.
- Due to an API limitation this requires using :meth:`Client.fetch_user`.
- Add ``reason`` keyword argument to more methods
- Add audit log events for threads
- Allow public threads to be created without a starter message
- Add :meth:`Guild.get_channel_or_thread` helper method
- Add full support for the new sticker API
- Add :func:`on_socket_event_type` event to get the event type of an event
- Add :attr:`TextChannel.default_auto_archive_duration`
- Add :class:`PartialMessageable` type to allow for sending messages to a channel using only its ``channel_id``.
- This is constructed with :meth:`Client.get_partial_messageable`.
- Add :meth:`Guild.active_threads` to get all of a guild's active threads.
- Add :attr:`Thread.members` to get all cached :class:`ThreadMember` instances of a thread.
- Add :meth:`Thread.fetch_members` to fetch all :class:`ThreadMember` instances of a thread.
- These two require :attr:`Intents.members` to be useful.
- Add support for guild avatars for members under :attr:`Member.guild_avatar`
- Add :attr:`User.display_avatar` and :attr:`Member.display_avatar` to get the user's displayed avatar.
- Add :attr:`Colour.brand_green` and :attr:`Colour.brand_red`
- |commands| :attr:`CommandOnCooldown.type` to get back the type of the cooldown since it was removed from :class:`Cooldown`
- Add :attr:`Guild.bots` and :attr:`Guild.humans`
Bug Fixes
~~~~~~~~~~~
- :class:`Channel` converters now work in DMs again
- Fix :attr:`Interaction.channel` being None in threads
- Change timeouts in :class:`ui.View` to work as documented
- :attr:`Message.__repr__` now shows the proper type, e.g. :class:`WebhookMessage` and :class:`InteractionMessage`
- Change :class:`Cooldown` handling to not reset token window when the number of tokens reaches 0
- Fix audit log permission construction breaking due to unexpected type errors.
- Fix :func:`on_thread_join` not dispatching when a thread is unarchived
- Fix :attr:`Message.guild` being None when a thread is unarchived due to a new message
- :class:`MessageConverter` now works with threads
- Retry requests when a 504 is hit
- Fix :attr:`Thread.slowmode_delay` not updating on edit
- Fix ``permissions_for`` for roles
- Update :attr:`Message.system_content` for newer message types
- Fix :class:`PartialMessage` not working with threads
- Fix crash with stage instances not having the documented ``discoverable_enabled`` key
- Fix some built-in checks not working with threads
- Fix :class:`SyncWebhook` not working in a multi-threaded context
- Fix :func:`on_thread_member_remove` not dispatching properly
- Fix :func:`on_typing` not dispatching for threads
- Update :attr:`Message.is_system` to work with newer message types
- Fix some enums like :class:`VerificationLevel` not being comparable.
- Fix ``io.BytesIO`` sources not working with ffmpeg players
- Fix :meth:`Client.fetch_channel` and :meth:`Guild.fetch_channel` not returning threads
.. _vp1p7p3:
v1.7.3