Migrating from discord.py
After the discontinuation of discord.py
(refer
this gist), many forks of the API wrapper branched
onward to maintain the library, in order to keep it updated with the latest features and Discord API changes - disnake
is one such fork.
Thus, if you've chosen disnake
as your fork of choice in order to implement interactions/components and other
features, this page will help you understand the changes in syntax, and aim for making your migrating process as smooth
as possible.
Differences between libraries
disnake
is based on discord.py 2.0
, which had major syntax changes from its previous version. Therefore, if you're
shifting to disnake
from a version of discord.py
lower than 2.0, you will have to make some important syntax changes
in your code. You can refer this page for the full
list of breaking changes in discord.py 2.0
, though we will list some primary API reference changes here:
- Methods and attributes that returned
TextChannel
, etc can now returnThread
. - Attributes that returned
Asset
are renamed, e.g. attributes ending with_url
(i.e.avatar_url
) are changed toavatar.url
.User.avatar
returnsNone
in case the default avatar is used. on_presence_update
replaceson_member_update
for updates toMember.status
andMember.activities
.- Webhooks are changed significantly:
WebhookAdapter
is removed, and synchronous requests usingrequests
is now insideSyncWebhook
. edit
methods no longer updates cache and instead returns modified instance.Client.logout
is removed; useClient.close
instead.Message.type
for replies are nowMessageType.reply
.Reaction.custom_emoji
property is changed toReaction.is_custom_emoji
method.missing_perms
attributes and arguments are renamed tomissing_permissions
.- Many arguments are now specified as positional-only or keyword-only; e.g.
oauth_url
now takes keyword-only arguments, and methods starting withget_
orfetch_
take positional-only arguments.
Changing requirements
In order to avoid conflicts between the libraries, you must uninstall discord.py
. You can do so by using the following
command in your terminal:
- Windows
- macOS
- Linux
py -3 -m pip uninstall discord
python3 -m pip uninstall discord
python3 -m pip uninstall discord
To install disnake
, you can follow the instructions on this page.
Rewriting your bot
As discussed above, rewriting your code from an older discord.py
version to disnake
will require some major syntax
changes. But if you're migrating from discord.py 2.0
, all that's left now is changing the library references
throughout the code, since the base code for both the libraries is practically the same.
There are two ways to switch between libraries:
Replace discord
with disnake
Import
disnake
into your code (and delete the lines where you importdiscord
).import disnake
from disnake.ext import commandsWith your favorite editor, replace every
discord
reference in your code withdisnake
(this is fairly simple, if your editor has a "Find & Replace" tool).
Import disnake as discord
Import disnake as discord
into your code (and delete the lines where you import discord
). This reduces the effort of
changing all references throughout your code.
import disnake as discord
from disnake.ext import commands
And that's it! Since disnake
is a fork of discord.py
, it inherits a lot of similarities - though we recommend you to
always run your code to fix any possible issues.