Skip to content

Latest commit

 

History

History
273 lines (195 loc) · 14.2 KB

migrating_to_v2.rst

File metadata and controls

273 lines (195 loc) · 14.2 KB
.. currentmodule:: discord

Migrating to v2.0

v2.0 introduced new Discord features and deprecated some old ones.

Part of the redesign involves making application commands and components. These changes include a new :class:`Bot` class, :class:`ui.View`, and a new :class:`ApplicationContext` class. If you're interested in creating them, please check out our :resource:`guide <guide>`.

Python Version Change

In order to make development easier and also to allow for our dependencies to upgrade to allow usage of 3.8 or higher, the library had to remove support for Python versions lower than 3.7, which essentially means that support for Python 3.7 and below has been dropped.

Major Model Changes

Below are major changes that have happened in v2.0:

Dropped User Accounts Support

Before v2.0, user accounts were supported. This has been against the spirit of the library and discord ToS and has been removed. Thus, these features that were only applicable to them are removed:

  • bot argument of :meth:`Client.start` and :meth:`Client.run`
  • afk argument of :meth:`Client.change_presence`
  • Classes Profile, Relationship, Call Message, Group Call
  • RelationshipType, HypeSquadHouse, PremiumType, UserContentFilter, FriendFlags, Theme
  • GroupChannel.add_recipients, remove_recipients, edit (NOTE: GroupChannel itself still remains)
  • Guild.ack
  • Client.self_bot
  • Client.fetch_user_profile
  • Message.call and ack
  • ClientUser.email, premium, premium_type, get_relationship, relationships, friends, blocked, create_group, edit_settings
  • Arguments of ClientUser.edit: password, new_password, email, house
  • User.relationship, mutual_friends, is_friend, is_blocked, block, unblock, remove_friend, send_friend_request, profile
  • Events: on_relationship_add and on_relationship_update

Timezone-aware Time

utcnow becomes now(datetime.timezone.utc). If you are constructing :class:`datetime.datetime`` yourself, pass tzinfo=datetime.timezone.utc.

embed = discord.Embed(
    title = "Pi Day 2021 in UTC",
    timestamp = datetime(2021, 3, 14, 15, 9, 2, tzinfo=timezone.utc)
)

Note that newly-added :meth:`utils.utcnow()` can be used as an alias of datetime.datetime.now(datetime.timezone.utc).

Asset Changes

Asset-related attributes that previously returned hash strings (e.g. :attr:`User.avatar`) now returns :class:`Asset`. :attr:`Asset.key` returns the hash from now on.

Before After
str(user.avatar_url) user.display_avatar.url
str(user.avatar_url_as(size=128)) user.display_avatar.with_size(128).url
str(user.avatar_url_as(size=128, static_format="png")) user.display_avatar.replace(size=128, static_format="png").url
str(user.avatar_url_as(size=128, static_format="png")) user.display_avatar.with_size(128).with_static_format("png").url
await user.avatar_url.read() await user.display_avatar.read()
str(emoji.url) emoji.url
str(emoji.url_as(size=32)) emoji.with_size(32).url
str(url_as(size=128, static_format="png")) emoji.replace(size=128, static_format="png").url
str(sticker.image_url) sticker.url
str(partialemoji.url) partialemoji.url

Webhook Changes

webhook = discord.SyncWebhook.from_url(
    f"https://discord.com/api/webhooks/{id}/{token}"
)
webhook.send("Hello from Pycord 2.0")
async with aiohttp.ClientSession() as session:
    webhook = discord.Webhook.partial(
        id,
        token,
        session=session
    )
    await webhook.send("Hello from Pycord 2.0")

Intents Changes

:attr:`Intents.message_content` is now a privileged intent. Disabling it causes :attr:`Message.content`, :attr:`Message.embeds`, :attr:`Message.components`, and :attr:`Message.attachments` to be empty (an empty string or an empty array), directly causing :class:`ext.commands.Command` s to not run. See here for more information.

Threads Introduced

The following methods and attributes can return :class:`Thread` objects:

Permission Changes

permissions_in has been removed in favor of checking the permissions of the channel for said user.

Before After
User.permissions_in abc.GuildChannel.permissions_for
Member.permissions_in abc.GuildChannel.permissions_for

Edit Method Behavior Change

edit methods of most classes no longer update the cache in-place, and instead returns the modified object.

Positional-Keyword Argument Split

The following are now positional only:

The following are now keyword only:

Event Changes

Message.type For Replies

:attr:`Message.type` now returns :attr:`MessageType.reply` for replies, instead of :attr:`MessageType.default`.

Sticker Changes

Type Changes

Many method arguments now reject None or return None.

Miscellaneous Changes

The following were removed:

The following were renamed:

The following were changed in behavior:

The following were changed in types:

Parting Words

The v2.0 of the library implemented a lot of new features. To implement newer features, such as slash commands, they can be seen on our :resource:`guide <guide>`.