2929 get_top_role ,
3030 create_thread_channel ,
3131 get_joint_id ,
32+ AcceptButton ,
33+ DenyButton ,
34+ ConfirmThreadCreationView
3235)
3336
3437logger = getLogger (__name__ )
@@ -1416,30 +1419,19 @@ async def create(
14161419 destination = recipient
14171420 else :
14181421 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" ]))
14191425 confirm = await destination .send (
14201426 embed = discord .Embed (
14211427 title = self .bot .config ["confirm_thread_creation_title" ],
14221428 description = self .bot .config ["confirm_thread_response" ],
1423- color = self .bot .main_color ,
1424- )
1429+ color = self .bot .main_color
1430+ ),
1431+ view = view
14251432 )
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 == None :
14431435 thread .cancelled = True
14441436 self .bot .loop .create_task (
14451437 destination .send (
@@ -1450,23 +1442,16 @@ async def create(
14501442 )
14511443 )
14521444 )
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 == 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
14611452 )
14621453 )
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+ )
14701455 if thread .cancelled :
14711456 del self .cache [recipient .id ]
14721457 return thread
0 commit comments