Skip to content

Commit 5d43030

Browse files
committed
Changed message after "?setup", fixed a problem when deleting log_channel and main_category
1 parent c87cc25 commit 5d43030

File tree

3 files changed

+36
-16
lines changed

3 files changed

+36
-16
lines changed

bot.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,9 @@ def log_channel(self):
147147
channel_id = self.config.get('log_channel_id')
148148
if channel_id is not None:
149149
return self.get_channel(int(channel_id))
150-
return self.main_category.channels[0]
150+
if self.main_category is not None:
151+
return self.main_category.channels[0]
152+
return None
151153

152154
@property
153155
def snippets(self):
@@ -463,6 +465,16 @@ async def on_guild_channel_delete(self, channel):
463465
return
464466

465467
if not isinstance(channel, discord.TextChannel):
468+
if self.config.get('main_category_id') == channel.id:
469+
await self.config.update({
470+
'main_category_id': None
471+
})
472+
return
473+
474+
if self.config.get('log_channel_id') == channel.id:
475+
await self.config.update({
476+
'log_channel_id': None
477+
})
466478
return
467479

468480
thread = await self.threads.find(channel=channel)

cogs/modmail.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ async def setup(self, ctx):
2727
"""Sets up a server for Modmail"""
2828
if self.bot.main_category:
2929
return await ctx.send(
30-
f'{self.bot.modmail_guild} is already set up.')
30+
f'{self.bot.modmail_guild} is already set up.'
31+
)
3132

3233
category = await self.bot.modmail_guild.create_category(
3334
name='Modmail',
@@ -40,15 +41,18 @@ async def setup(self, ctx):
4041
name='bot-logs', category=category
4142
)
4243

43-
await log_channel.edit(
44-
topic='You can delete this channel '
45-
'if you set up your own log channel.'
44+
embed = discord.Embed(
45+
title='Friendly Reminder:',
46+
description='You may use the `config set log_channel_id '
47+
'<channel-id>` command to set up a custom log channel'
48+
', then you can delete the default '
49+
f'{log_channel.mention} channel.',
50+
color=discord.Color.blurple()
4651
)
4752

48-
await log_channel.send(
49-
'Use the `config set log_channel_id` '
50-
'command to set up a custom log channel.'
51-
)
53+
embed.set_footer(text=f'Type "{self.bot.prefix}help" '
54+
'for a complete list of commands.')
55+
await log_channel.send(embed=embed)
5256

5357
self.bot.config['main_category_id'] = category.id
5458
self.bot.config['log_channel_id'] = log_channel.id

core/thread.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -491,13 +491,17 @@ async def _find_from_channel(self, channel):
491491
# BUG: When discord fails to create channel topic.
492492
# search through message history
493493
elif channel.topic is None:
494-
async for message in channel.history(limit=100):
495-
if message.embeds:
496-
embed = message.embeds[0]
497-
if embed.footer.text:
498-
user_id = match_user_id(embed.footer.text)
499-
if user_id != -1:
500-
break
494+
try:
495+
async for message in channel.history(limit=100):
496+
if message.embeds:
497+
embed = message.embeds[0]
498+
if embed.footer.text:
499+
user_id = match_user_id(embed.footer.text)
500+
if user_id != -1:
501+
break
502+
except discord.NotFound:
503+
# When the channel's deleted.
504+
pass
501505

502506
if user_id != -1:
503507
if user_id in self.cache:

0 commit comments

Comments
 (0)