Skip to content

Commit dd5e060

Browse files
committed
type checks when SelectDefaultvalue insts
1 parent 31663ba commit dd5e060

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

discord/ui/select.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,23 @@ def _handle_default_values(
258258

259259
ret = []
260260

261+
valid_default_types = {
262+
ComponentType.user_select: (SelectDefaultValueType.user,),
263+
ComponentType.role_select: (SelectDefaultValueType.role,),
264+
ComponentType.channel_select: (SelectDefaultValueType.channel,),
265+
ComponentType.mentionable_select: (SelectDefaultValueType.user, SelectDefaultValueType.role),
266+
}
267+
261268
for dv in default_values:
262269
if isinstance(dv, SelectDefaultValue):
270+
try:
271+
valid_types = valid_default_types[select_type]
272+
except KeyError:
273+
raise TypeError(f"select default values are not allowed for this select type ({select_type.name})")
274+
275+
if dv.type not in valid_types:
276+
raise TypeError(f"{dv.type.name} is not a valid select default value for selects of type {select_type.name}")
277+
263278
ret.append(dv)
264279
continue
265280
if isinstance(dv, str):

0 commit comments

Comments
 (0)