Migrating to v2.x¶
v2.0 is the latest major and breaking release of this library. This version not only brings the long-awaited new API features like interactions, threads etc. but also brings many breaking changes that can affect all the bots updating to v2 from v1.x.
This migration guide covers the prominent additions, bug fixes and most importantly breaking changes to help you easily migrate to v2. We highly suggest you reading this guide to avoid running into unexpected issues.
Python requirement¶
Prior v2, In v1.x, The minimum Python version required was 3.5, This is not the case in v2. To make development easier and allow our dependencies to adapt new versions, Support for Python version lower then 3.8 has been dropped.
You now need Python 3.8 or higher to use this library.
Removal of Non-bot accounts support¶
v2.0 removes all the previously depreciated user endpoints. Please note that userbots are against Discord ToS. This library will not provide coverage to such things that are against ToS.
This includes the following methods and attributes:
Bot.fetch_user_profile()ClientUser.unblock()ClientUser.relationshipsClientUser.friendsClientUser.create_group()ClientUser.edit_settings()User.relationshipsUser.mutual_friends()User.is_friend()User.is_blocked()User.block()User.unblock()User.remove_friend()User.send_friend_request()User.profile()Member.relationshipsMember.mutual_friends()Member.is_friend()Member.is_blocked()Member.block()Member.unblock()Member.remove_friend()Member.send_friend_request()Member.profile()The
afkparameter fromClient.change_presence()Events:
on_relationship_addandon_relationship_updateClasses:
Profile,Relationship,CallMessage,GroupCall
Removals and Deprecations¶
Certain methods, attributes or parameters etc. have been removed or deprecated in v2.0 in favor of some other methods. The below table comprehensively lists some removed things with reasons and the methods to be replaced with:
Deprecated |
In favor of |
Extra info (if any) |
|
||
|
||
|
none (See info) |
Had no use and was unnecessary. |
|
none (See info) |
Bots no longer get these events. |
|
|
|
|
|
Was deprecated since v1.5. |
|
||
|
none (See info) |
Discord no longer provides this. |
|
none (See info) |
Userbots are no longer supported |
|
Renaming and fixes¶
Certain things are renamed and fixed in v2.x, Here’s a list:
commands.MissingPermissions.missing_perms->missing_permissionsColor.blurple->Color.og_blurple[*]StickerType, an enum of sticker formats, is renamed toStickerFormatType. [**]Reaction.custom_emojiproperty ->Reaction.is_custom_emoji()method.Message.typefor replies are nowMessageType.replyAll getters and fetchers methods now take arguments as positional-only.
i.e Client.get_member(id=...) is no longer supported, you must specify id as positional argument. i.e Client.get_member(id)
* IntegrationAccount.id is now str, instead of int, due to Discord changes.
[*] Color.blurple() returns the new blurple color whereas Color.og_blurple() returns
old one.
[**] Old name is used for a new enum with different purpose (checking if the sticker is guild sticker or Nitro sticker)
Webhook Types Split¶
Previously, Webhook had one class Webhook for both asynchronous and synchronous operations.
In v2.x, This has been splitted to Webhook and SyncWebhook for async and
sync operations respectively.
Before:
from diskord import Webhook, RequestsWebhookAdapter, AsyncWebhookAdapter
webhook = Webhook.from_url('url-here', adapter=RequestsWebhookAdapter()) # for sync
webhook = Webhook.from_url('url-here', adapter=AsyncWebhookAdapter(session)) # for async
Now:
from diskord import Webhook, SyncWebhook
import aiohttp
async with aiohttp.ClientSession() as session: # async
webhook = Webhook.partial(
id,
token,
session=session
)
await webhook.send("Hello world.")
webhook = SyncWebhook.from_url('url-here') # for sync
WebhookandWebhookMessageare now always asynchronouns. For synchronouns use (requests), useSyncWebhookandSyncWebhookMessage.WebhookAdapter,AsyncWebhookAdapter, andRequestsWebhookAdapterare removed, since they are unnecessary.adapterarguments ofWebhook.partial()andWebhook.from_url()are removed. Sessions are now passed directly to partial/from_url.
Assets Redesign¶
Assets have been completely redesigned in v2.x.
Asset-related attributes that previously returned hash strings (e.g.
User.avatar) now returnsAsset.Asset.keyreturns the hash from now on.Class.x_urlandClass.x_url_asare removed.Asset.replace()orAsset.with_x()methods can be used to get specific asset sizes or types.Emoji.urlandPartialEmoji.urlare nowstr.Emoji.save()andEmoji.read()are added to save or read emojis.Emoji.url_asandPartialEmoji.url_asare removed.Some
AuditLogDiffattributes now returnAssetinstead ofstr:splash,icon,avatarUser.avatarreturnsNoneif the avatar is not set and is instead the default avatar; useUser.display_avatarfor pre-2.0 behavior.Attributes that returned Asset are renamed, e.g. attributes ending with
_url(i.e.avatar_url) are changed toavatar.url.User.avatarreturns None in case the default avatar is used.
Use of timezone aware time¶
TL;DR: utcnow becomes now(datetime.timezone.utc). If you are constructing datetime yourself,
pass tzinfo=datetime.timezone.utc.
Example:
embed = diskord.Embed(
title = "Embed with timestamp",
timestamp = datetime(2021, 3, 14, 15, 9, 2, tzinfo=timezone.utc)
)
# or
embed = diskord.Embed(
title='Embed with timestamp',
timestamp=diskord.utils.utcnow()
)
Note that newly-added utils.utcnow() can be used as a short-hand of datetime.datetime.now(datetime.timezone.utc).
Edit Behaviour Changes¶
edit methods of most classes no longer update the cache in-place, and instead returns the
modified instance.
on_socket_raw_receive() behavior¶
on_socket_raw_receive is no longer dispatched for incomplete data, and the value passed is
always decompressed and decoded to str. Previously, when received a multi-part
zlib-compressed binary message, on_socket_raw_receive() was dispatched on all messages
with the compressed, encoded bytes.
Context attributes¶
The following Context attributes can now be None:
* prefix
* command
* invoked_with
* invoked_subcommand.
Threads Support¶
Thread support was added in v2.0 and with this addition, There’re some breaking changes.
TL;DR: Most Methods and attributes that returned TextChannel, etc can now return Thread.
Client.get_channel()can now returnThread.Client.fetch_channel()andGuild.fetch_channel()can now returnThread.ext.commands.NSFWChannelRequired.channelcan now returnThread.ext.commands.ChannelNotReadable.argumentcan now returnThread.Message.channelcan now returnThread.
Splitting up of status activity listeners¶
on_member_update() event is no longer dispatched for status/activity changes.
Use on_presence_update() instead.
Additions¶
These are not breaking changes but few major additions in v2.x.
Threads support
Application Commands i.e Slash commands, Context menu commands etc.
Partial support for application command extensions i.e Checks, Converters
Full Stickers Support
Message Components and interactions
Stage instances support
Guild Welcome Screens
User banners support
Removal helpers for embeds
Integration create/delete/edit events.
Support for editing guild widgets
Support for bot integrations
Invite targets for voice channel invites
Color class can now be typecasted to
intAdd Discord Certified Moderator user flag
Add support for explicit time parameter in ext.tasks.
Add
fetch_messageto webhooks.Add
ApplicationFlagsAdd
Guild.delete_custom_emoji()methodAdd
on_raw_typing()event for DM typing.Add
Template.urlAdd
ext.Command.extrasto attach additional data to command.Add
Activity.buttons
There are many other minor changes that’re not listed here.