Migration From discord.py¶
-
NAFF requires python 3.10 (as compared to dpy's 3.5), you may need to upgrade python.
- If you see
ERROR: Could not find a version that satisfies the requirement naff (from versions: none)
when trying topip install NAFF
, this is your problem.
- If you see
-
Classes/Models
- Your client is
naff.Client
. (Note that commands are a first-class feature, so this is a replacement to bothdiscord.Client
anddiscord.ext.commands.Bot
) - Cogs are
Extensions
. Member
is not a subclass ofUser
, if you're usingisinstance
, you'll want to check both explicitly.
- Your client is
-
Extensions (Cogs)
- These work mostly the same, with a few notable changes:
- Your setup function doesn't need to do
bot.add_cog()
. Simply callMyCog(bot)
, and it'll automatically register itself. - Extensions already define
self.bot
, you don't need to do that in your__init__
function. - For a full example, see here
-
Event handlers
- Register event handlers with
@naff.listen
- Where possible, we use the official names for events, most notably
on_message_create
instead of dpy'son_message
. - A full list can be found here.
- Event details are stored on a model, passed as a single parameter. (eg:
on_member_update(before, after)
becomeson_member_update(event)
, where event has a.before
and.after
. - For more details, read the Events guide.
- Register event handlers with
-
Migrating your commands
- If you were already using dpy's command extension, migrating to slash commands is fairly simple. You just need to convert the decorators as per the Slash Commands guide
- If you wish to keep using prefixed commands (sometimes called message or text-based commands), you can use our
@naff.prefixed_command
decorator, which has an extensive guide for them. The syntax should be very similar to discord.py with a few exceptions. - If you were manually handling commands with
on_message
, you'll probably need to figure it out yourself, as this guide doesn't know how you wrote your parser. Consider using the provided command handlers.
Note
This guide was written based on the experiences of porting a small handful of bots. There may be gotchas that we did not encounter. If you run into anything you'd like to have known, let us know in our Discord, and we'll add it to this document.