@@ -1115,16 +1115,16 @@ async def find(
1115
1115
try :
1116
1116
await thread .wait_until_ready ()
1117
1117
except asyncio .CancelledError :
1118
- logger .warning ("Thread for %s cancelled, abort creating " , recipient )
1118
+ logger .warning ("Thread for %s cancelled. " , recipient )
1119
1119
return thread
1120
1120
else :
1121
- if not thread .channel or not self .bot .get_channel (thread .channel .id ):
1121
+ if not thread .cancelled and (
1122
+ not thread .channel or not self .bot .get_channel (thread .channel .id )
1123
+ ):
1122
1124
logger .warning (
1123
1125
"Found existing thread for %s but the channel is invalid." , recipient_id
1124
1126
)
1125
- self .bot .loop .create_task (
1126
- thread .close (closer = self .bot .user , silent = True , delete_channel = False )
1127
- )
1127
+ await thread .close (closer = self .bot .user , silent = True , delete_channel = False )
1128
1128
thread = None
1129
1129
else :
1130
1130
channel = discord .utils .get (
@@ -1186,7 +1186,7 @@ async def create(
1186
1186
try :
1187
1187
await thread .wait_until_ready ()
1188
1188
except asyncio .CancelledError :
1189
- logger .warning ("Thread for %s cancelled, abort creating" , recipient )
1189
+ logger .warning ("Thread for %s cancelled, abort creating. " , recipient )
1190
1190
return thread
1191
1191
else :
1192
1192
if thread .channel and self .bot .get_channel (thread .channel .id ):
@@ -1195,9 +1195,7 @@ async def create(
1195
1195
logger .warning (
1196
1196
"Found an existing thread for %s, closing previous thread." , recipient
1197
1197
)
1198
- self .bot .loop .create_task (
1199
- thread .close (closer = self .bot .user , silent = True , delete_channel = False )
1200
- )
1198
+ await thread .close (closer = self .bot .user , silent = True , delete_channel = False )
1201
1199
1202
1200
thread = Thread (self , recipient )
1203
1201
@@ -1231,9 +1229,11 @@ async def create(
1231
1229
)
1232
1230
accept_emoji = self .bot .config ["confirm_thread_creation_accept" ]
1233
1231
deny_emoji = self .bot .config ["confirm_thread_creation_deny" ]
1234
- await confirm .add_reaction (accept_emoji )
1235
- await asyncio .sleep (0.2 )
1236
- await confirm .add_reaction (deny_emoji )
1232
+ emojis = [accept_emoji , deny_emoji ]
1233
+ for emoji in emojis :
1234
+ await confirm .add_reaction (emoji )
1235
+ await asyncio .sleep (0.2 )
1236
+
1237
1237
try :
1238
1238
r , _ = await self .bot .wait_for (
1239
1239
"reaction_add" ,
@@ -1245,29 +1245,31 @@ async def create(
1245
1245
)
1246
1246
except asyncio .TimeoutError :
1247
1247
thread .cancelled = True
1248
-
1249
- await confirm .remove_reaction (accept_emoji , self .bot .user )
1250
- await asyncio .sleep (0.2 )
1251
- await confirm .remove_reaction (deny_emoji , self .bot .user )
1252
- await destination .send (
1253
- embed = discord .Embed (
1254
- title = "Cancelled" , description = "Timed out" , color = self .bot .error_color
1248
+ self .bot .loop .create_task (
1249
+ destination .send (
1250
+ embed = discord .Embed (
1251
+ title = "Cancelled" , description = "Timed out" , color = self .bot .error_color
1252
+ )
1255
1253
)
1256
1254
)
1257
- del self .cache [recipient .id ]
1258
- return thread
1259
1255
else :
1260
1256
if str (r .emoji ) == deny_emoji :
1261
1257
thread .cancelled = True
1258
+ self .bot .loop .create_task (
1259
+ destination .send (
1260
+ embed = discord .Embed (title = "Cancelled" , color = self .bot .error_color )
1261
+ )
1262
+ )
1262
1263
1263
- await confirm .remove_reaction (accept_emoji , self .bot .user )
1264
+ async def remove_reactions ():
1265
+ for emoji in emojis :
1266
+ await confirm .remove_reaction (emoji , self .bot .user )
1264
1267
await asyncio .sleep (0.2 )
1265
- await confirm .remove_reaction (deny_emoji , self .bot .user )
1266
- await destination .send (
1267
- embed = discord .Embed (title = "Cancelled" , color = self .bot .error_color )
1268
- )
1269
- del self .cache [recipient .id ]
1270
- return thread
1268
+
1269
+ self .bot .loop .create_task (remove_reactions ())
1270
+ if thread .cancelled :
1271
+ del self .cache [recipient .id ]
1272
+ return thread
1271
1273
1272
1274
self .bot .loop .create_task (
1273
1275
thread .setup (creator = creator , category = category , initial_message = message )
0 commit comments