26
26
from __future__ import annotations
27
27
28
28
import datetime
29
- from typing import TYPE_CHECKING , Any , Callable , Iterable , Mapping , TypeVar , overload
29
+ from typing import (
30
+ TYPE_CHECKING ,
31
+ Any ,
32
+ Callable ,
33
+ Iterable ,
34
+ Mapping ,
35
+ Sequence ,
36
+ TypeVar ,
37
+ overload ,
38
+ )
30
39
31
40
import discord .abc
32
41
45
54
)
46
55
from .errors import ClientException , InvalidArgument
47
56
from .file import File
48
- from .flags import ChannelFlags
57
+ from .flags import ChannelFlags , MessageFlags
49
58
from .invite import Invite
50
59
from .iterators import ArchivedThreadIterator
51
60
from .mixins import Hashable
71
80
72
81
if TYPE_CHECKING :
73
82
from .abc import Snowflake , SnowflakeTime
83
+ from .embeds import Embed
74
84
from .guild import Guild
75
85
from .guild import GuildChannel as GuildChannelType
76
86
from .member import Member , VoiceState
87
+ from .mentions import AllowedMentions
77
88
from .message import EmojiInputType , Message , PartialMessage
78
89
from .role import Role
79
90
from .state import ConnectionState
91
+ from .sticker import GuildSticker , StickerItem
80
92
from .types .channel import CategoryChannel as CategoryChannelPayload
81
93
from .types .channel import DMChannel as DMChannelPayload
82
94
from .types .channel import ForumChannel as ForumChannelPayload
87
99
from .types .channel import VoiceChannel as VoiceChannelPayload
88
100
from .types .snowflake import SnowflakeList
89
101
from .types .threads import ThreadArchiveDuration
102
+ from .ui .view import View
90
103
from .user import BaseUser , ClientUser , User
91
104
from .webhook import Webhook
92
105
@@ -1181,18 +1194,20 @@ async def edit(self, *, reason=None, **options):
1181
1194
async def create_thread (
1182
1195
self ,
1183
1196
name : str ,
1184
- content = None ,
1197
+ content : str | None = None ,
1185
1198
* ,
1186
- embed = None ,
1187
- embeds = None ,
1188
- file = None ,
1189
- files = None ,
1190
- stickers = None ,
1191
- delete_message_after = None ,
1192
- nonce = None ,
1193
- allowed_mentions = None ,
1194
- view = None ,
1195
- applied_tags = None ,
1199
+ embed : Embed | None = None ,
1200
+ embeds : list [Embed ] | None = None ,
1201
+ file : File | None = None ,
1202
+ files : list [File ] | None = None ,
1203
+ stickers : Sequence [GuildSticker | StickerItem ] | None = None ,
1204
+ delete_message_after : float | None = None ,
1205
+ nonce : int | str | None = None ,
1206
+ allowed_mentions : AllowedMentions | None = None ,
1207
+ view : View | None = None ,
1208
+ applied_tags : list [ForumTag ] | None = None ,
1209
+ suppress : bool = False ,
1210
+ silent : bool = False ,
1196
1211
auto_archive_duration : ThreadArchiveDuration = MISSING ,
1197
1212
slowmode_delay : int = MISSING ,
1198
1213
reason : str | None = None ,
@@ -1292,13 +1307,24 @@ async def create_thread(
1292
1307
else :
1293
1308
allowed_mentions = allowed_mentions .to_dict ()
1294
1309
1310
+ flags = MessageFlags (
1311
+ suppress_embeds = bool (suppress ),
1312
+ suppress_notifications = bool (silent ),
1313
+ )
1314
+
1295
1315
if view :
1296
1316
if not hasattr (view , "__discord_ui_view__" ):
1297
1317
raise InvalidArgument (
1298
1318
f"view parameter must be View not { view .__class__ !r} "
1299
1319
)
1300
1320
1301
1321
components = view .to_components ()
1322
+ if view .is_components_v2 ():
1323
+ if embeds or content :
1324
+ raise TypeError (
1325
+ "cannot send embeds or content with a view using v2 component logic"
1326
+ )
1327
+ flags .is_components_v2 = True
1302
1328
else :
1303
1329
components = None
1304
1330
@@ -1337,6 +1363,7 @@ async def create_thread(
1337
1363
or self .default_auto_archive_duration ,
1338
1364
rate_limit_per_user = slowmode_delay or self .slowmode_delay ,
1339
1365
applied_tags = applied_tags ,
1366
+ flags = flags .value ,
1340
1367
reason = reason ,
1341
1368
)
1342
1369
finally :
@@ -1346,7 +1373,7 @@ async def create_thread(
1346
1373
1347
1374
ret = Thread (guild = self .guild , state = self ._state , data = data )
1348
1375
msg = ret .get_partial_message (int (data ["last_message_id" ]))
1349
- if view :
1376
+ if view and view . is_dispatchable () :
1350
1377
state .store_view (view , msg .id )
1351
1378
1352
1379
if delete_message_after is not None :
0 commit comments