From ed6394575fdd8080eada0b1053712322b367c72d Mon Sep 17 00:00:00 2001 From: LordOfPolls Date: Tue, 21 Mar 2023 08:50:49 +0000 Subject: [PATCH 1/4] docs: add naff migration guide --- ...rom D.py.md => 100 Migration From D.py.md} | 0 docs/src/Guides/99 2.x Migration_NAFF.md | 52 +++++++++++++++++++ docs/src/Guides/index.md | 8 ++- 3 files changed, 59 insertions(+), 1 deletion(-) rename docs/src/Guides/{99 Migration From D.py.md => 100 Migration From D.py.md} (100%) create mode 100644 docs/src/Guides/99 2.x Migration_NAFF.md diff --git a/docs/src/Guides/99 Migration From D.py.md b/docs/src/Guides/100 Migration From D.py.md similarity index 100% rename from docs/src/Guides/99 Migration From D.py.md rename to docs/src/Guides/100 Migration From D.py.md diff --git a/docs/src/Guides/99 2.x Migration_NAFF.md b/docs/src/Guides/99 2.x Migration_NAFF.md new file mode 100644 index 000000000..346457d6d --- /dev/null +++ b/docs/src/Guides/99 2.x Migration_NAFF.md @@ -0,0 +1,52 @@ +Oh hey! So you're migrating from NAFF to interactions.py? Well lets get you sorted. + +First and foremost, you'll need to install the new library. You can do this by running `pip install interactions.py` in your terminal. +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. + +## Prefixed Commands +I.py moves prefixed commands to an extension, rather than being a part of the client. So to use them you'll nneed to load them. +```python +from interactions import Client, Intents +from interactions.ext import prefixed_commands + +# guild messages are included in the default intents ipy uses +# if you wish for the prefix to be anything but mentioning the bot, +# guild message content will also be required +client = Client(..., intents=Intents.GUILD_MESSAGES | ...) +prefixed_commands.setup(client) +``` +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). + +## Hybrid Commands +For now, hybrid commands are not supported, but they will be in the future. + +## Enums +To get us on the same page. Enums are a way of defining a set of constants. For a Discord example, ButtonStyles. +In v5, enums are no longer plural. So `ButtonStyles` is now `ButtonStyle`. This applies to all enums in the library. + +## StringSelectMenu +`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(*[...])`. +Alternatively, I recommend this syntax: +```python +StringSelectMenu( + "Thing 1", "Thing 2", "Thing 3", + placeholder="Pick a thing" +) +``` +This is much more readable, and removes useless boilerplate. + +## Modals +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(*[...])`. +Again, the same recommendation applies here: +```python +Modal( + ShortText(label="Short Input Text", custom_id="short_text"), + ParagraphText(label="Long Input Text", custom_id="long_text"), + title="My Modal", +) +``` + +## Kwargs Vs. Args +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. +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. + diff --git a/docs/src/Guides/index.md b/docs/src/Guides/index.md index e29713294..b6fbdc433 100644 --- a/docs/src/Guides/index.md +++ b/docs/src/Guides/index.md @@ -100,7 +100,7 @@ These guides are meant to help you get started with the library and offer a poin Oh damn, your bot is getting pretty big, huh? Well I guess its time we discuss sharding. -- [__:material-frequently-asked-questions: Migration from discord.py__](99 Migration From D.py.md) +- [__:material-frequently-asked-questions: Migration from discord.py__](100 Migration From D.py.md) --- @@ -112,5 +112,11 @@ These guides are meant to help you get started with the library and offer a poin How do I migrate from i.py v4.4 to v5? +- [__:material-package-up: 2.x Migration Guide__](99 2.x Migration_NAFF.md) + + --- + + How do I migrate from NAFF to i.py v5? + From e2af4daa32f04589c04723c540fdd9a76680e854 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 21 Mar 2023 08:51:38 +0000 Subject: [PATCH 2/4] ci: correct from checks. --- docs/src/Guides/99 2.x Migration_NAFF.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/src/Guides/99 2.x Migration_NAFF.md b/docs/src/Guides/99 2.x Migration_NAFF.md index 346457d6d..9401349b7 100644 --- a/docs/src/Guides/99 2.x Migration_NAFF.md +++ b/docs/src/Guides/99 2.x Migration_NAFF.md @@ -1,4 +1,4 @@ -Oh hey! So you're migrating from NAFF to interactions.py? Well lets get you sorted. +Oh hey! So you're migrating from NAFF to interactions.py? Well lets get you sorted. First and foremost, you'll need to install the new library. You can do this by running `pip install interactions.py` in your terminal. 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. @@ -21,7 +21,7 @@ From here it's more or less the same as before. You can find a guide on how to u For now, hybrid commands are not supported, but they will be in the future. ## Enums -To get us on the same page. Enums are a way of defining a set of constants. For a Discord example, ButtonStyles. +To get us on the same page. Enums are a way of defining a set of constants. For a Discord example, ButtonStyles. In v5, enums are no longer plural. So `ButtonStyles` is now `ButtonStyle`. This applies to all enums in the library. ## StringSelectMenu @@ -49,4 +49,3 @@ Modal( ## Kwargs Vs. Args 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. 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. - From fcdd806da631b038f0912d6f48ca35ea4dd62503 Mon Sep 17 00:00:00 2001 From: LordOfPolls Date: Tue, 21 Mar 2023 16:28:18 +0000 Subject: [PATCH 3/4] docs: dont encourage wildcard imports --- docs/src/Guides/99 2.x Migration_NAFF.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/Guides/99 2.x Migration_NAFF.md b/docs/src/Guides/99 2.x Migration_NAFF.md index 9401349b7..e70e4fda3 100644 --- a/docs/src/Guides/99 2.x Migration_NAFF.md +++ b/docs/src/Guides/99 2.x Migration_NAFF.md @@ -1,7 +1,7 @@ Oh hey! So you're migrating from NAFF to interactions.py? Well lets get you sorted. First and foremost, you'll need to install the new library. You can do this by running `pip install interactions.py` in your terminal. -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. +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. ## Prefixed Commands I.py moves prefixed commands to an extension, rather than being a part of the client. So to use them you'll nneed to load them. From aac258c7051b21fb53b23d8a849428a36820d32f Mon Sep 17 00:00:00 2001 From: Damego Date: Fri, 24 Mar 2023 17:05:30 +0500 Subject: [PATCH 4/4] Update docs/src/Guides/99 2.x Migration_NAFF.md Co-authored-by: VincentRPS --- docs/src/Guides/99 2.x Migration_NAFF.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/Guides/99 2.x Migration_NAFF.md b/docs/src/Guides/99 2.x Migration_NAFF.md index e70e4fda3..734c3560b 100644 --- a/docs/src/Guides/99 2.x Migration_NAFF.md +++ b/docs/src/Guides/99 2.x Migration_NAFF.md @@ -4,7 +4,7 @@ First and foremost, you'll need to install the new library. You can do this by r 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. ## Prefixed Commands -I.py moves prefixed commands to an extension, rather than being a part of the client. So to use them you'll nneed to load them. +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. ```python from interactions import Client, Intents from interactions.ext import prefixed_commands