Skip to content

Commit 6ba54b4

Browse files
NeloBlivionpre-commit-ci[bot]LulalabyDorukyum
authored
feat: implement onboarding features (Pycord-Development#2127)
* initial onboarding impl. * Implement main edit function * implement shorthand edit * typo * better doc * misc * fix enums * fix repr * docs adjust * fix edit args * import fixes * docs clarify * final touches? * randint...? * style(pre-commit): auto fixes from pre-commit.com hooks * typefix * style(pre-commit): auto fixes from pre-commit.com hooks * docs updates * cleanup * style(pre-commit): auto fixes from pre-commit.com hooks * Update enum Co-authored-by: Dorukyum <[email protected]> Signed-off-by: UK <[email protected]> * Update enums Co-authored-by: Dorukyum <[email protected]> Signed-off-by: UK <[email protected]> * Replace _guild with guild Co-authored-by: Dorukyum <[email protected]> Signed-off-by: UK <[email protected]> * Add new PromptOptions fields Co-authored-by: Dorukyum <[email protected]> Signed-off-by: UK <[email protected]> * Update to_dict for emoji changes and exchange randint for generate_snowflake * style(pre-commit): auto fixes from pre-commit.com hooks * Final push * style(pre-commit): auto fixes from pre-commit.com hooks * remove debug lines * thanku doruk Co-authored-by: Dorukyum <[email protected]> Signed-off-by: UK <[email protected]> * chore: minimal changes * chore: finalize * chore: promise this is the last --------- Signed-off-by: Lala Sabathil <[email protected]> Signed-off-by: UK <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Lala Sabathil <[email protected]> Co-authored-by: Dorukyum <[email protected]>
1 parent 90f9023 commit 6ba54b4

File tree

9 files changed

+734
-0
lines changed

9 files changed

+734
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ These changes are available on the `master` branch, but have not yet been releas
8686
([#2322](https://github.com/Pycord-Development/pycord/pull/2322))
8787
- Added `User.avatar_decoration`.
8888
([#2131](https://github.com/Pycord-Development/pycord/pull/2131))
89+
- Added support for guild onboarding related features.
90+
([#2127](https://github.com/Pycord-Development/pycord/pull/2127))
8991

9092
### Changed
9193

discord/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
from .mentions import *
5454
from .message import *
5555
from .object import *
56+
from .onboarding import *
5657
from .partial_emoji import *
5758
from .permissions import *
5859
from .player import *

discord/enums.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@
6767
"AutoModActionType",
6868
"AutoModKeywordPresetType",
6969
"ApplicationRoleConnectionMetadataType",
70+
"PromptType",
71+
"OnboardingMode",
7072
"ReactionType",
7173
)
7274

@@ -428,6 +430,11 @@ class AuditLogAction(Enum):
428430
auto_moderation_user_communication_disabled = 145
429431
creator_monetization_request_created = 150
430432
creator_monetization_terms_accepted = 151
433+
onboarding_question_create = 163
434+
onboarding_question_update = 164
435+
onboarding_update = 167
436+
server_guide_create = 190
437+
server_guide_update = 191
431438

432439
@property
433440
def category(self) -> AuditLogActionCategory | None:
@@ -490,6 +497,11 @@ def category(self) -> AuditLogActionCategory | None:
490497
AuditLogAction.auto_moderation_user_communication_disabled: None,
491498
AuditLogAction.creator_monetization_request_created: None,
492499
AuditLogAction.creator_monetization_terms_accepted: None,
500+
AuditLogAction.onboarding_question_create: AuditLogActionCategory.create,
501+
AuditLogAction.onboarding_question_update: AuditLogActionCategory.update,
502+
AuditLogAction.onboarding_update: AuditLogActionCategory.update,
503+
AuditLogAction.server_guide_create: AuditLogActionCategory.create,
504+
AuditLogAction.server_guide_update: AuditLogActionCategory.update,
493505
}
494506
return lookup[self]
495507

@@ -530,6 +542,12 @@ def target_type(self) -> str | None:
530542
return "application_command_permission"
531543
elif v < 146:
532544
return "auto_moderation_rule"
545+
elif v < 152:
546+
return "monetization"
547+
elif v < 168:
548+
return "onboarding"
549+
elif v < 192:
550+
return "server_guide"
533551

534552

535553
class UserFlags(Enum):
@@ -946,6 +964,20 @@ class ApplicationRoleConnectionMetadataType(Enum):
946964
boolean_not_equal = 8
947965

948966

967+
class PromptType(Enum):
968+
"""Guild Onboarding Prompt Type"""
969+
970+
multiple_choice = 0
971+
dropdown = 1
972+
973+
974+
class OnboardingMode(Enum):
975+
"""Guild Onboarding Mode"""
976+
977+
default = 0
978+
advanced = 1
979+
980+
949981
class ReactionType(Enum):
950982
"""The reaction type"""
951983

discord/guild.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
from .iterators import AuditLogIterator, BanIterator, MemberIterator
7272
from .member import Member, VoiceState
7373
from .mixins import Hashable
74+
from .onboarding import Onboarding
7475
from .permissions import PermissionOverwrite
7576
from .role import Role
7677
from .scheduled_events import ScheduledEvent, ScheduledEventLocation
@@ -3842,6 +3843,88 @@ async def create_auto_moderation_rule(
38423843
)
38433844
return AutoModRule(state=self._state, data=data)
38443845

3846+
async def onboarding(self):
3847+
"""|coro|
3848+
3849+
Returns the :class:`Onboarding` flow for the guild.
3850+
3851+
.. versionadded:: 2.5
3852+
3853+
Returns
3854+
-------
3855+
:class:`Onboarding`
3856+
The onboarding flow for the guild.
3857+
3858+
Raises
3859+
------
3860+
HTTPException
3861+
Retrieving the onboarding flow failed somehow.
3862+
"""
3863+
data = await self._state.http.get_onboarding(self.id)
3864+
return Onboarding(data=data, guild=self)
3865+
3866+
async def edit_onboarding(
3867+
self,
3868+
*,
3869+
prompts: list[OnboardingPrompt] | None = MISSING,
3870+
default_channels: list[Snowflake] | None = MISSING,
3871+
enabled: bool | None = MISSING,
3872+
mode: OnboardingMode | None = MISSING,
3873+
reason: str | None = MISSING,
3874+
) -> Onboarding:
3875+
"""|coro|
3876+
3877+
A shorthand for :attr:`Onboarding.edit` without fetching the onboarding flow.
3878+
3879+
You must have the :attr:`~Permissions.manage_guild` and :attr:`~Permissions.manage_roles` permissions in the
3880+
guild to do this.
3881+
3882+
Parameters
3883+
----------
3884+
3885+
prompts: Optional[List[:class:`OnboardingPrompt`]]
3886+
The new list of prompts for this flow.
3887+
default_channels: Optional[List[:class:`Snowflake`]]
3888+
The new default channels that users are opted into.
3889+
enabled: Optional[:class:`bool`]
3890+
Whether onboarding should be enabled. Setting this to ``True`` requires
3891+
the guild to have ``COMMUNITY`` in :attr:`~Guild.features` and at
3892+
least 7 ``default_channels``.
3893+
mode: Optional[:class:`OnboardingMode`]
3894+
The new onboarding mode.
3895+
reason: Optional[:class:`str`]
3896+
The reason that shows up on Audit log.
3897+
3898+
Returns
3899+
-------
3900+
:class:`Onboarding`
3901+
The updated onboarding flow.
3902+
3903+
Raises
3904+
------
3905+
3906+
HTTPException
3907+
Editing the onboarding flow failed somehow.
3908+
Forbidden
3909+
You don't have permissions to edit the onboarding flow.
3910+
"""
3911+
3912+
fields: dict[str, Any] = {}
3913+
if prompts is not MISSING:
3914+
fields["prompts"] = [prompt.to_dict() for prompt in prompts]
3915+
3916+
if default_channels is not MISSING:
3917+
fields["default_channel_ids"] = [channel.id for channel in default_channels]
3918+
3919+
if enabled is not MISSING:
3920+
fields["enabled"] = enabled
3921+
3922+
if mode is not MISSING:
3923+
fields["mode"] = mode.value
3924+
3925+
new = await self._state.http.edit_onboarding(self.id, fields, reason=reason)
3926+
return Onboarding(data=new, guild=self)
3927+
38453928
async def delete_auto_moderation_rule(
38463929
self,
38473930
id: int,

discord/http.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
invite,
7070
member,
7171
message,
72+
onboarding,
7273
role,
7374
scheduled_events,
7475
sticker,
@@ -2884,6 +2885,29 @@ def update_application_role_connection_metadata_records(
28842885
)
28852886
return self.request(r, json=payload)
28862887

2888+
# Onboarding
2889+
2890+
def get_onboarding(self, guild_id: Snowflake) -> Response[onboarding.Onboarding]:
2891+
return self.request(
2892+
Route("GET", "/guilds/{guild_id}/onboarding", guild_id=guild_id)
2893+
)
2894+
2895+
def edit_onboarding(
2896+
self, guild_id: Snowflake, payload: Any, *, reason: str | None = None
2897+
) -> Response[onboarding.Onboarding]:
2898+
keys = (
2899+
"prompts",
2900+
"default_channel_ids",
2901+
"enabled",
2902+
"mode",
2903+
)
2904+
payload = {key: val for key, val in payload.items() if key in keys}
2905+
return self.request(
2906+
Route("PUT", "/guilds/{guild_id}/onboarding", guild_id=guild_id),
2907+
json=payload,
2908+
reason=reason,
2909+
)
2910+
28872911
# Misc
28882912

28892913
def application_info(self) -> Response[appinfo.AppInfo]:

0 commit comments

Comments
 (0)