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
48
57
)
49
58
from .errors import ClientException , InvalidArgument
50
59
from .file import File
51
- from .flags import ChannelFlags
60
+ from .flags import ChannelFlags , MessageFlags
52
61
from .invite import Invite
53
62
from .iterators import ArchivedThreadIterator
54
63
from .mixins import Hashable
74
83
75
84
if TYPE_CHECKING :
76
85
from .abc import Snowflake , SnowflakeTime
86
+ from .embeds import Embed
77
87
from .guild import Guild
78
88
from .guild import GuildChannel as GuildChannelType
79
89
from .member import Member , VoiceState
90
+ from .mentions import AllowedMentions
80
91
from .message import EmojiInputType , Message , PartialMessage
81
92
from .role import Role
82
93
from .state import ConnectionState
94
+ from .sticker import GuildSticker , StickerItem
83
95
from .types .channel import CategoryChannel as CategoryChannelPayload
84
96
from .types .channel import DMChannel as DMChannelPayload
85
97
from .types .channel import ForumChannel as ForumChannelPayload
90
102
from .types .channel import VoiceChannel as VoiceChannelPayload
91
103
from .types .snowflake import SnowflakeList
92
104
from .types .threads import ThreadArchiveDuration
105
+ from .ui .view import View
93
106
from .user import BaseUser , ClientUser , User
94
107
from .webhook import Webhook
95
108
@@ -1187,18 +1200,20 @@ async def edit(self, *, reason=None, **options):
1187
1200
async def create_thread (
1188
1201
self ,
1189
1202
name : str ,
1190
- content = None ,
1203
+ content : str | None = None ,
1191
1204
* ,
1192
- embed = None ,
1193
- embeds = None ,
1194
- file = None ,
1195
- files = None ,
1196
- stickers = None ,
1197
- delete_message_after = None ,
1198
- nonce = None ,
1199
- allowed_mentions = None ,
1200
- view = None ,
1201
- applied_tags = None ,
1205
+ embed : Embed | None = None ,
1206
+ embeds : list [Embed ] | None = None ,
1207
+ file : File | None = None ,
1208
+ files : list [File ] | None = None ,
1209
+ stickers : Sequence [GuildSticker | StickerItem ] | None = None ,
1210
+ delete_message_after : float | None = None ,
1211
+ nonce : int | str | None = None ,
1212
+ allowed_mentions : AllowedMentions | None = None ,
1213
+ view : View | None = None ,
1214
+ applied_tags : list [ForumTag ] | None = None ,
1215
+ suppress : bool = False ,
1216
+ silent : bool = False ,
1202
1217
auto_archive_duration : ThreadArchiveDuration = MISSING ,
1203
1218
slowmode_delay : int = MISSING ,
1204
1219
reason : str | None = None ,
@@ -1298,13 +1313,24 @@ async def create_thread(
1298
1313
else :
1299
1314
allowed_mentions = allowed_mentions .to_dict ()
1300
1315
1316
+ flags = MessageFlags (
1317
+ suppress_embeds = bool (suppress ),
1318
+ suppress_notifications = bool (silent ),
1319
+ )
1320
+
1301
1321
if view :
1302
1322
if not hasattr (view , "__discord_ui_view__" ):
1303
1323
raise InvalidArgument (
1304
1324
f"view parameter must be View not { view .__class__ !r} "
1305
1325
)
1306
1326
1307
1327
components = view .to_components ()
1328
+ if view .is_components_v2 ():
1329
+ if embeds or content :
1330
+ raise TypeError (
1331
+ "cannot send embeds or content with a view using v2 component logic"
1332
+ )
1333
+ flags .is_components_v2 = True
1308
1334
else :
1309
1335
components = None
1310
1336
@@ -1343,6 +1369,7 @@ async def create_thread(
1343
1369
or self .default_auto_archive_duration ,
1344
1370
rate_limit_per_user = slowmode_delay or self .slowmode_delay ,
1345
1371
applied_tags = applied_tags ,
1372
+ flags = flags .value ,
1346
1373
reason = reason ,
1347
1374
)
1348
1375
finally :
@@ -1352,7 +1379,7 @@ async def create_thread(
1352
1379
1353
1380
ret = Thread (guild = self .guild , state = self ._state , data = data )
1354
1381
msg = ret .get_partial_message (int (data ["last_message_id" ]))
1355
- if view :
1382
+ if view and view . is_dispatchable () :
1356
1383
state .store_view (view , msg .id )
1357
1384
1358
1385
if delete_message_after is not None :
0 commit comments