|
| 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. |
0 commit comments