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 Bot
class, ui.View
, and a new ApplicationContext
class. If you’re interested in creating them, please check out our 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 ofClient.start()
andClient.run()
afk
argument ofClient.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
andack
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
andon_relationship_update
Timezone-aware Time¶
utcnow
becomes now(datetime.timezone.utc)
. If you are constructing 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 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. User.avatar
) now returns Asset
. Asset.key
returns the hash from now on.
Class.x_url
andClass.x_url_as
are removed.Asset.replace()
orAsset.with_x()
methods can be used to get specific asset sizes or types.Emoji.url
andPartialEmoji.url
are nowstr
.Emoji.save()
andEmoji.read()
are added to save or read emojis.Emoji.url_as
andPartialEmoji.url_as
are removed.Some
AuditLogDiff
attributes now returnAsset
instead ofstr
:AuditLogDiff.splash
,AuditLogDiff.icon
,AuditLogDiff.avatar
User.avatar
returnsNone
if the avatar is not set and is instead the default avatar; useUser.display_avatar
for pre-2.0 behavior.
Before |
After |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Webhook Changes¶
Webhook
andWebhookMessage
are now always asynchronous. For synchronous use (requests
), useSyncWebhook
andSyncWebhookMessage
.WebhookAdapter
,AsyncWebhookAdapter
, andRequestsWebhookAdapter
are removed, since they are unnecessary.adapter
arguments ofWebhook.partial()
andWebhook.from_url()
are removed. Sessions are now passed directly topartial
/from_url
.
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¶
Intents.message_content
is now a privileged intent. Disabling it causes Message.content
,
Message.embeds
, Message.components
, and Message.attachments
to be empty (an empty string
or an empty array), directly causing ext.commands.Command
s to not run.
See here for more information.
Threads Introduced¶
The following methods and attributes can return Thread
objects:
Permission Changes¶
permissions_in
has been removed in favor of checking the permissions of the channel for said user.
Before |
After |
|
|
|
|
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¶
on_presence_update()
replaces on_member_update for updates toMember.status
andMember.activities
.on_private_channel_create/delete
will no longer be dispatched due to Discord changes.on_socket_raw_receive()
is no longer dispatched for incomplete data, and the value passed is always decompressed and decoded tostr
. Previously, when received a multi-part zlib-compressed binary message,on_socket_raw_receive()
was dispatched on all messages with the compressed, encodedbytes
.
Message.type For Replies¶
Message.type
now returns MessageType.reply
for replies, instead of MessageType.default
.
Sticker Changes¶
Sticker.preview_image
was removed as Discord no longer provides the data.StickerType
, an enum of sticker formats, is renamed toStickerFormatType
. Old name is used for a new enum with different purpose (checking if the sticker is guild sticker or Nitro sticker).Message.stickers
is now List[StickerItem
] instead of List[Sticker
]. WhileStickerItem
supports some operations of previousSticker
,description
andpack_id
attributes do not exist.Sticker
can be fetched viaStickerItem.fetch()
method.Sticker.image
is removed.Sticker
can still be fetched viaSticker.read()
orSticker.save()
and its URL can be accessed viaSticker.url
, just like newEmoji
.Due to the introduction of
GuildSticker
,Sticker.tags
is removed from the parent classSticker
and moved toStandardSticker.tags
.
Type Changes¶
Many method arguments now reject None
or return None
.
DMChannel.recipient
is now optional, and will returnNone
in many cases.User.avatar
returnsNone
if the avatar is not set and is instead the default avatar.Guild.create_text_channel
’stopic
argument no longer acceptsNone
.Guild.vanity_invite
can now returnNone
.Template.edit
’sname
argument no longer acceptsNone
.Member.edit
’sroles
argument no longer acceptsNone
.Bot.add_listener
andBot.remove_listener
’sname
arguments no longer acceptNone
.The following
ext.commands.Context
attributes can now beNone
:prefix
,command
,invoked_with
,invoked_subcommand
.ext.commands.Command.help
can now beNone
.
Miscellaneous Changes¶
The following were removed:
Client.request_offline_members
Client.logout
ExtensionNotFound.original
MemberCacheFlags.online
guild_subscriptions
argument ofClient
fetch_offline_members
argument ofClient
HelpCommand.clean_prefix
moved toext.commands.Context.clean_prefix
VerificationLevel.table_flip
(alias ofhigh
) was removed.extreme
,very_high
, anddouble_table_flip
attributes were removed and replaced withVerificationLevel.highest
.
The following were renamed:
Colour.blurple
is renamed toColour.og_blurple
, andColour.blurple
now returns the newer color.missing_perms
arguments and attributes ofext.commands.MissingPermissions
andext.commands.BotMissingPermissions
are renamed tomissing_permissions
.
The following were changed in behavior:
Embed
that has a value is always considered truthy. Previously it only considered text fields.Bot.add_cog()
now raises an error when a cog with the same name is already registered.override
argument can be used to bring back the 1.x behavior.StageChannel.edit()
can no longer edittopic
. UseStageInstance.edit()
instead.StageChannel.clone()
no longer clones its topic.
The following were changed in types:
ext.commands.Command.clean_params
is now adict
, notOrderedDict
.Reaction.custom_emoji
is nowReaction.is_custom_emoji
for consistency.IntegrationAccount.id
is nowstr
, instead ofint
, due to Discord changes.AuditLogDiff.type
is now Union[ChannelType
,StickerType
], instead ofChannelType
.
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 guide.