58
58
"component_callback" ,
59
59
"ComponentCommand" ,
60
60
"context_menu" ,
61
+ "user_context_menu" ,
62
+ "message_context_menu" ,
61
63
"ContextMenu" ,
62
64
"global_autocomplete" ,
63
65
"GlobalAutoComplete" ,
@@ -725,7 +727,7 @@ def group(
725
727
726
728
def subcommand (
727
729
self ,
728
- sub_cmd_name : LocalisedName | str ,
730
+ sub_cmd_name : Absent [ LocalisedName | str ] = MISSING ,
729
731
group_name : LocalisedName | str = None ,
730
732
sub_cmd_description : Absent [LocalisedDesc | str ] = MISSING ,
731
733
group_description : Absent [LocalisedDesc | str ] = MISSING ,
@@ -734,13 +736,15 @@ def subcommand(
734
736
inherit_checks : bool = True ,
735
737
) -> Callable [..., "SlashCommand" ]:
736
738
def wrapper (call : Callable [..., Coroutine ]) -> "SlashCommand" :
737
- nonlocal sub_cmd_description
739
+ nonlocal sub_cmd_name , sub_cmd_description
738
740
739
741
if not asyncio .iscoroutinefunction (call ):
740
742
raise TypeError ("Subcommand must be coroutine" )
741
743
742
744
if sub_cmd_description is MISSING :
743
745
sub_cmd_description = call .__doc__ or "No Description Set"
746
+ if sub_cmd_name is MISSING :
747
+ sub_cmd_name = call .__name__
744
748
745
749
return SlashCommand (
746
750
name = self .name ,
@@ -863,7 +867,7 @@ def decorator(func: Callable) -> GlobalAutoComplete:
863
867
864
868
865
869
def slash_command (
866
- name : str | LocalisedName ,
870
+ name : Absent [ str | LocalisedName ] = MISSING ,
867
871
* ,
868
872
description : Absent [str | LocalisedDesc ] = MISSING ,
869
873
scopes : Absent [List ["Snowflake_Type" ]] = MISSING ,
@@ -885,7 +889,7 @@ def slash_command(
885
889
one of the future ui updates.
886
890
887
891
Args:
888
- name: 1-32 character name of the command
892
+ name: 1-32 character name of the command, defaults to the name of the coroutine.
889
893
description: 1-100 character description of the command
890
894
scopes: The scope this command exists within
891
895
options: The parameters for the command, max 25
@@ -913,12 +917,16 @@ def wrapper(func: AsyncCallable) -> SlashCommand:
913
917
else :
914
918
perm = func .default_member_permissions
915
919
920
+ _name = name
921
+ if _name is MISSING :
922
+ _name = func .__name__
923
+
916
924
_description = description
917
925
if _description is MISSING :
918
926
_description = func .__doc__ or "No Description Set"
919
927
920
928
cmd = SlashCommand (
921
- name = name ,
929
+ name = _name ,
922
930
group_name = group_name ,
923
931
group_description = group_description ,
924
932
sub_cmd_name = sub_cmd_name ,
@@ -941,7 +949,7 @@ def subcommand(
941
949
base : str | LocalisedName ,
942
950
* ,
943
951
subcommand_group : Optional [str | LocalisedName ] = None ,
944
- name : Optional [str | LocalisedName ] = None ,
952
+ name : Absent [str | LocalisedName ] = MISSING ,
945
953
description : Absent [str | LocalisedDesc ] = MISSING ,
946
954
base_description : Optional [str | LocalisedDesc ] = None ,
947
955
base_desc : Optional [str | LocalisedDesc ] = None ,
@@ -980,6 +988,10 @@ def wrapper(func: AsyncCallable) -> SlashCommand:
980
988
if not asyncio .iscoroutinefunction (func ):
981
989
raise ValueError ("Commands must be coroutines" )
982
990
991
+ _name = name
992
+ if _name is MISSING :
993
+ _name = func .__name__
994
+
983
995
_description = description
984
996
if _description is MISSING :
985
997
_description = func .__doc__ or "No Description Set"
@@ -989,7 +1001,7 @@ def wrapper(func: AsyncCallable) -> SlashCommand:
989
1001
description = (base_description or base_desc ) or "No Description Set" ,
990
1002
group_name = subcommand_group ,
991
1003
group_description = (subcommand_group_description or sub_group_desc ) or "No Description Set" ,
992
- sub_cmd_name = name ,
1004
+ sub_cmd_name = _name ,
993
1005
sub_cmd_description = _description ,
994
1006
default_member_permissions = base_default_member_permissions ,
995
1007
dm_permission = base_dm_permission ,
@@ -1004,7 +1016,8 @@ def wrapper(func: AsyncCallable) -> SlashCommand:
1004
1016
1005
1017
1006
1018
def context_menu (
1007
- name : str | LocalisedName ,
1019
+ name : Absent [str | LocalisedName ] = MISSING ,
1020
+ * ,
1008
1021
context_type : "CommandType" ,
1009
1022
scopes : Absent [List ["Snowflake_Type" ]] = MISSING ,
1010
1023
default_member_permissions : Optional ["Permissions" ] = None ,
@@ -1014,7 +1027,7 @@ def context_menu(
1014
1027
A decorator to declare a coroutine as a Context Menu.
1015
1028
1016
1029
Args:
1017
- name: 1-32 character name of the context menu
1030
+ name: 1-32 character name of the context menu, defaults to the name of the coroutine.
1018
1031
context_type: The type of context menu
1019
1032
scopes: The scope this command exists within
1020
1033
default_member_permissions: What permissions members need to have by default to use this command.
@@ -1036,8 +1049,12 @@ def wrapper(func: AsyncCallable) -> ContextMenu:
1036
1049
else :
1037
1050
perm = func .default_member_permissions
1038
1051
1052
+ _name = name
1053
+ if _name is MISSING :
1054
+ _name = func .__name__
1055
+
1039
1056
cmd = ContextMenu (
1040
- name = name ,
1057
+ name = _name ,
1041
1058
type = context_type ,
1042
1059
scopes = scopes or [GLOBAL_SCOPE ],
1043
1060
default_member_permissions = perm ,
@@ -1049,6 +1066,64 @@ def wrapper(func: AsyncCallable) -> ContextMenu:
1049
1066
return wrapper
1050
1067
1051
1068
1069
+ def user_context_menu (
1070
+ name : Absent [str | LocalisedName ] = MISSING ,
1071
+ * ,
1072
+ scopes : Absent [List ["Snowflake_Type" ]] = MISSING ,
1073
+ default_member_permissions : Optional ["Permissions" ] = None ,
1074
+ dm_permission : bool = True ,
1075
+ ) -> Callable [[AsyncCallable ], ContextMenu ]:
1076
+ """
1077
+ A decorator to declare a coroutine as a User Context Menu.
1078
+
1079
+ Args:
1080
+ name: 1-32 character name of the context menu, defaults to the name of the coroutine.
1081
+ scopes: The scope this command exists within
1082
+ default_member_permissions: What permissions members need to have by default to use this command.
1083
+ dm_permission: Should this command be available in DMs.
1084
+
1085
+ Returns:
1086
+ ContextMenu object
1087
+
1088
+ """
1089
+ return context_menu (
1090
+ name ,
1091
+ context_type = CommandType .USER ,
1092
+ scopes = scopes ,
1093
+ default_member_permissions = default_member_permissions ,
1094
+ dm_permission = dm_permission ,
1095
+ )
1096
+
1097
+
1098
+ def message_context_menu (
1099
+ name : Absent [str | LocalisedName ] = MISSING ,
1100
+ * ,
1101
+ scopes : Absent [List ["Snowflake_Type" ]] = MISSING ,
1102
+ default_member_permissions : Optional ["Permissions" ] = None ,
1103
+ dm_permission : bool = True ,
1104
+ ) -> Callable [[AsyncCallable ], ContextMenu ]:
1105
+ """
1106
+ A decorator to declare a coroutine as a Message Context Menu.
1107
+
1108
+ Args:
1109
+ name: 1-32 character name of the context menu, defaults to the name of the coroutine.
1110
+ scopes: The scope this command exists within
1111
+ default_member_permissions: What permissions members need to have by default to use this command.
1112
+ dm_permission: Should this command be available in DMs.
1113
+
1114
+ Returns:
1115
+ ContextMenu object
1116
+
1117
+ """
1118
+ return context_menu (
1119
+ name ,
1120
+ context_type = CommandType .MESSAGE ,
1121
+ scopes = scopes ,
1122
+ default_member_permissions = default_member_permissions ,
1123
+ dm_permission = dm_permission ,
1124
+ )
1125
+
1126
+
1052
1127
def component_callback (* custom_id : str ) -> Callable [[AsyncCallable ], ComponentCommand ]:
1053
1128
"""
1054
1129
Register a coroutine as a component callback.
0 commit comments