Skip to content

Commit a63d1b8

Browse files
committed
Added handling for when the channel's deleted when the bot's down
1 parent 9c4de11 commit a63d1b8

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

bot.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,18 +204,26 @@ async def on_ready(self):
204204
await self.threads.populate_cache()
205205
await self.config.update()
206206

207-
closures = self.config.get('closures', {})
207+
closures = self.config.get('closures', {}).copy()
208208
print(closures) # for debugging
209209
for recipient_id, items in closures.items():
210210
after = (datetime.datetime.fromisoformat(items['time']) -
211211
datetime.datetime.utcnow()).total_seconds()
212212
if after < 0:
213213
after = 0
214214
recipient = self.get_user(int(recipient_id))
215-
print(recipient)
215+
216216
thread = await self.threads.find(
217217
recipient=recipient)
218-
print(thread)
218+
219+
if not thread:
220+
# If the recipient is gone or channel is deleted
221+
closures = self.config.get('closures', {})
222+
closures.pop(str(recipient_id))
223+
self.config['closures'] = closures
224+
await self.config.update()
225+
continue
226+
219227
# TODO: Retrieve messages/replies when bot is down, from history?
220228
await thread.close(closer=self.get_user(items['closer_id']),
221229
after=after,

0 commit comments

Comments
 (0)