Skip to content

Commit d29c758

Browse files
LordOfPollspre-commit-ci[bot]DamegoVincentRPS
authored
docs: add naff migration guide (#1307)
* docs: add naff migration guide * ci: correct from checks. * docs: dont encourage wildcard imports * Update docs/src/Guides/99 2.x Migration_NAFF.md Co-authored-by: VincentRPS <vincentbusiness55@gmail.com> --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Damego <damego.dev@gmail.com> Co-authored-by: VincentRPS <vincentbusiness55@gmail.com>
1 parent 8879c85 commit d29c758

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed
File renamed without changes.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
Oh hey! So you're migrating from NAFF to interactions.py? Well lets get you sorted.
2+
3+
First and foremost, you'll need to install the new library. You can do this by running `pip install interactions.py` in your terminal.
4+
Then, the first thing you'll need to do is change your imports. You'll need to change `from naff import _` to `from interactions import _`. To be honest, assuming your code is relatively simple, you should be able to use find and replace to do this.
5+
6+
## Prefixed Commands
7+
I.py moves prefixed commands to an extension, rather than being a part of the client. So to use them you'll need to load them.
8+
```python
9+
from interactions import Client, Intents
10+
from interactions.ext import prefixed_commands
11+
12+
# guild messages are included in the default intents ipy uses
13+
# if you wish for the prefix to be anything but mentioning the bot,
14+
# guild message content will also be required
15+
client = Client(..., intents=Intents.GUILD_MESSAGES | ...)
16+
prefixed_commands.setup(client)
17+
```
18+
From here it's more or less the same as before. You can find a guide on how to use prefixed commands [here](/Guides/26 Prefixed Commands.md).
19+
20+
## Hybrid Commands
21+
For now, hybrid commands are not supported, but they will be in the future.
22+
23+
## Enums
24+
To get us on the same page. Enums are a way of defining a set of constants. For a Discord example, ButtonStyles.
25+
In v5, enums are no longer plural. So `ButtonStyles` is now `ButtonStyle`. This applies to all enums in the library.
26+
27+
## StringSelectMenu
28+
`StringSelectMenu` now takes it's options as positional arguments, rather than a list. This means that you can no longer do `StringSelectMenu(options=[...])`, instead the quickest way to do it is `StringSelectMenu(*[...])`.
29+
Alternatively, I recommend this syntax:
30+
```python
31+
StringSelectMenu(
32+
"Thing 1", "Thing 2", "Thing 3",
33+
placeholder="Pick a thing"
34+
)
35+
```
36+
This is much more readable, and removes useless boilerplate.
37+
38+
## Modals
39+
Much like `StringSelectMenu`, Modals now take their children as positional arguments, rather than a list. This means that you can no longer do `Modal(components=[...])`, instead the quickest way to do it is `Modal(*[...])`.
40+
Again, the same recommendation applies here:
41+
```python
42+
Modal(
43+
ShortText(label="Short Input Text", custom_id="short_text"),
44+
ParagraphText(label="Long Input Text", custom_id="long_text"),
45+
title="My Modal",
46+
)
47+
```
48+
49+
## Kwargs Vs. Args
50+
V5 prefers kwargs over args. This means for the majority of methods and objects, they expect their arguments to be passed as kwargs, rather than args. This is to make the library more readable, and to make it easier to add new arguments in the future.
51+
The **only** exceptions to this are list-like objects, like `ActionRow`, `StringSelectMenu`, `Modal`, where the children are passed as args in order to keep the syntax clean.

docs/src/Guides/index.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ These guides are meant to help you get started with the library and offer a poin
100100

101101
Oh damn, your bot is getting pretty big, huh? Well I guess its time we discuss sharding.
102102

103-
- [__:material-frequently-asked-questions: Migration from discord.py__](99 Migration From D.py.md)
103+
- [__:material-frequently-asked-questions: Migration from discord.py__](100 Migration From D.py.md)
104104

105105
---
106106

@@ -112,5 +112,11 @@ These guides are meant to help you get started with the library and offer a poin
112112

113113
How do I migrate from i.py v4.4 to v5?
114114

115+
- [__:material-package-up: 2.x Migration Guide__](99 2.x Migration_NAFF.md)
116+
117+
---
118+
119+
How do I migrate from NAFF to i.py v5?
120+
115121

116122
</div>

0 commit comments

Comments
 (0)