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
@@ -1183,18 +1196,20 @@ async def edit(self, *, reason=None, **options):
1183
1196
async def create_thread (
1184
1197
self ,
1185
1198
name : str ,
1186
- content = None ,
1199
+ content : str | None = None ,
1187
1200
* ,
1188
- embed = None ,
1189
- embeds = None ,
1190
- file = None ,
1191
- files = None ,
1192
- stickers = None ,
1193
- delete_message_after = None ,
1194
- nonce = None ,
1195
- allowed_mentions = None ,
1196
- view = None ,
1197
- applied_tags = None ,
1201
+ embed : Embed | None = None ,
1202
+ embeds : list [Embed ] | None = None ,
1203
+ file : File | None = None ,
1204
+ files : list [File ] | None = None ,
1205
+ stickers : Sequence [GuildSticker | StickerItem ] | None = None ,
1206
+ delete_message_after : float | None = None ,
1207
+ nonce : int | str | None = None ,
1208
+ allowed_mentions : AllowedMentions | None = None ,
1209
+ view : View | None = None ,
1210
+ applied_tags : list [ForumTag ] | None = None ,
1211
+ suppress : bool = False ,
1212
+ silent : bool = False ,
1198
1213
auto_archive_duration : ThreadArchiveDuration = MISSING ,
1199
1214
slowmode_delay : int = MISSING ,
1200
1215
reason : str | None = None ,
@@ -1294,13 +1309,24 @@ async def create_thread(
1294
1309
else :
1295
1310
allowed_mentions = allowed_mentions .to_dict ()
1296
1311
1312
+ flags = MessageFlags (
1313
+ suppress_embeds = bool (suppress ),
1314
+ suppress_notifications = bool (silent ),
1315
+ )
1316
+
1297
1317
if view :
1298
1318
if not hasattr (view , "__discord_ui_view__" ):
1299
1319
raise InvalidArgument (
1300
1320
f"view parameter must be View not { view .__class__ !r} "
1301
1321
)
1302
1322
1303
1323
components = view .to_components ()
1324
+ if view .is_components_v2 ():
1325
+ if embeds or content :
1326
+ raise TypeError (
1327
+ "cannot send embeds or content with a view using v2 component logic"
1328
+ )
1329
+ flags .is_components_v2 = True
1304
1330
else :
1305
1331
components = None
1306
1332
@@ -1339,6 +1365,7 @@ async def create_thread(
1339
1365
or self .default_auto_archive_duration ,
1340
1366
rate_limit_per_user = slowmode_delay or self .slowmode_delay ,
1341
1367
applied_tags = applied_tags ,
1368
+ flags = flags .value ,
1342
1369
reason = reason ,
1343
1370
)
1344
1371
finally :
@@ -1348,7 +1375,7 @@ async def create_thread(
1348
1375
1349
1376
ret = Thread (guild = self .guild , state = self ._state , data = data )
1350
1377
msg = ret .get_partial_message (int (data ["last_message_id" ]))
1351
- if view :
1378
+ if view and view . is_dispatchable () :
1352
1379
state .store_view (view , msg .id )
1353
1380
1354
1381
if delete_message_after is not None :
0 commit comments