29
29
get_top_role ,
30
30
create_thread_channel ,
31
31
get_joint_id ,
32
+ AcceptButton ,
33
+ DenyButton ,
34
+ ConfirmThreadCreationView
32
35
)
33
36
34
37
logger = getLogger (__name__ )
@@ -1416,30 +1419,19 @@ async def create(
1416
1419
destination = recipient
1417
1420
else :
1418
1421
destination = message .channel
1422
+ view = ConfirmThreadCreationView ()
1423
+ view .add_item (AcceptButton (self .bot .config ["confirm_thread_creation_accept" ]))
1424
+ view .add_item (DenyButton (self .bot .config ["confirm_thread_creation_deny" ]))
1419
1425
confirm = await destination .send (
1420
1426
embed = discord .Embed (
1421
1427
title = self .bot .config ["confirm_thread_creation_title" ],
1422
1428
description = self .bot .config ["confirm_thread_response" ],
1423
- color = self .bot .main_color ,
1424
- )
1429
+ color = self .bot .main_color
1430
+ ),
1431
+ view = view
1425
1432
)
1426
- accept_emoji = self .bot .config ["confirm_thread_creation_accept" ]
1427
- deny_emoji = self .bot .config ["confirm_thread_creation_deny" ]
1428
- emojis = [accept_emoji , deny_emoji ]
1429
- for emoji in emojis :
1430
- await confirm .add_reaction (emoji )
1431
- await asyncio .sleep (0.2 )
1432
-
1433
- try :
1434
- r , _ = await self .bot .wait_for (
1435
- "reaction_add" ,
1436
- check = lambda r , u : u .id == recipient .id
1437
- and r .message .id == confirm .id
1438
- and r .message .channel .id == confirm .channel .id
1439
- and str (r .emoji ) in (accept_emoji , deny_emoji ),
1440
- timeout = 20 ,
1441
- )
1442
- except asyncio .TimeoutError :
1433
+ await view .wait ()
1434
+ if view .value is None :
1443
1435
thread .cancelled = True
1444
1436
self .bot .loop .create_task (
1445
1437
destination .send (
@@ -1450,23 +1442,16 @@ async def create(
1450
1442
)
1451
1443
)
1452
1444
)
1453
- else :
1454
- if str (r .emoji ) == deny_emoji :
1455
- thread .cancelled = True
1456
- self .bot .loop .create_task (
1457
- destination .send (
1458
- embed = discord .Embed (
1459
- title = self .bot .config ["thread_cancelled" ], color = self .bot .error_color
1460
- )
1445
+ await confirm .edit (view = None )
1446
+ if view .value is False :
1447
+ thread .cancelled = True
1448
+ self .bot .loop .create_task (
1449
+ destination .send (
1450
+ embed = discord .Embed (
1451
+ title = self .bot .config ["thread_cancelled" ], color = self .bot .error_color
1461
1452
)
1462
1453
)
1463
-
1464
- async def remove_reactions ():
1465
- for emoji in emojis :
1466
- await confirm .remove_reaction (emoji , self .bot .user )
1467
- await asyncio .sleep (0.2 )
1468
-
1469
- self .bot .loop .create_task (remove_reactions ())
1454
+ )
1470
1455
if thread .cancelled :
1471
1456
del self .cache [recipient .id ]
1472
1457
return thread
0 commit comments