Skip to content

Commit cde98e9

Browse files
CordilaCordila
authored andcommitted
Fix guild icon not set issue
1 parent b04ac78 commit cde98e9

File tree

4 files changed

+28
-16
lines changed

4 files changed

+28
-16
lines changed

bot.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@ def __init__(self):
8787
self.plugin_db = PluginDatabaseClient(self) # Deprecated
8888
self.startup()
8989

90+
def get_guild_icon(self, guild: typing.Optional[discord.Guild]) -> str:
91+
if guild is None:
92+
guild = self.guild
93+
if guild.icon is None:
94+
return self.user.display_avatar.url
95+
return guild.icon_url
96+
9097
def _resolve_snippet(self, name: str) -> typing.Optional[str]:
9198
"""
9299
Get actual snippet names from direct aliases to snippets.
@@ -913,7 +920,10 @@ async def process_dm_modmail(self, message: discord.Message) -> None:
913920
color=self.error_color,
914921
description=self.config["disabled_new_thread_response"],
915922
)
916-
embed.set_footer(text=self.config["disabled_new_thread_footer"], icon_url=self.guild.icon.url)
923+
embed.set_footer(
924+
text=self.config["disabled_new_thread_footer"],
925+
icon_url=self.get_guild_icon(guild=message.guild),
926+
)
917927
logger.info("A new thread was blocked from %s due to disabled Modmail.", message.author)
918928
await self.add_reaction(message, blocked_emoji)
919929
return await message.channel.send(embed=embed)
@@ -928,7 +938,7 @@ async def process_dm_modmail(self, message: discord.Message) -> None:
928938
)
929939
embed.set_footer(
930940
text=self.config["disabled_current_thread_footer"],
931-
icon_url=self.guild.icon.url,
941+
icon_url=self.get_guild_icon(guild=message.guild),
932942
)
933943
logger.info("A message was blocked from %s due to disabled Modmail.", message.author)
934944
await self.add_reaction(message, blocked_emoji)
@@ -1335,7 +1345,7 @@ async def handle_react_to_contact(self, payload):
13351345
)
13361346
embed.set_footer(
13371347
text=self.config["disabled_new_thread_footer"],
1338-
icon_url=self.guild.icon.url,
1348+
icon_url=self.get_guild_icon(guild=channel.guild),
13391349
)
13401350
logger.info(
13411351
"A new thread using react to contact was blocked from %s due to disabled Modmail.",

cogs/modmail.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,15 @@ async def snippet(self, ctx, *, name: str.lower = None):
160160
color=self.bot.error_color, description="You dont have any snippets at the moment."
161161
)
162162
embed.set_footer(text=f'Check "{self.bot.prefix}help snippet add" to add a snippet.')
163-
embed.set_author(name="Snippets", icon_url=ctx.guild.icon.url)
163+
embed.set_author(name="Snippets", icon_url=self.bot.get_guild_icon(guild=ctx.guild))
164164
return await ctx.send(embed=embed)
165165

166166
embeds = []
167167

168168
for i, names in enumerate(zip_longest(*(iter(sorted(self.bot.snippets)),) * 15)):
169169
description = format_description(i, names)
170170
embed = discord.Embed(color=self.bot.main_color, description=description)
171-
embed.set_author(name="Snippets", icon_url=ctx.guild.icon.url)
171+
embed.set_author(name="Snippets", icon_url=self.bot.get_guild_icon(guild=ctx.guild))
172172
embeds.append(embed)
173173

174174
session = EmbedPaginatorSession(ctx, *embeds)
@@ -1031,7 +1031,7 @@ async def anonadduser(self, ctx, *users_arg: Union[discord.Member, discord.Role,
10311031
name = tag
10321032
avatar_url = self.bot.config["anon_avatar_url"]
10331033
if avatar_url is None:
1034-
avatar_url = self.bot.guild.icon.url
1034+
avatar_url = self.bot.get_guild_icon(guild=ctx.guild)
10351035
em.set_footer(text=name, icon_url=avatar_url)
10361036

10371037
for u in users:
@@ -1120,7 +1120,7 @@ async def anonremoveuser(self, ctx, *users_arg: Union[discord.Member, discord.Ro
11201120
name = tag
11211121
avatar_url = self.bot.config["anon_avatar_url"]
11221122
if avatar_url is None:
1123-
avatar_url = self.bot.guild.icon.url
1123+
avatar_url = self.bot.get_guild_icon(guild=ctx.guild)
11241124
em.set_footer(text=name, icon_url=avatar_url)
11251125

11261126
for u in users:
@@ -1200,7 +1200,7 @@ async def logs_closed_by(self, ctx, *, user: User = None):
12001200
user = user if user is not None else ctx.author
12011201

12021202
entries = await self.bot.api.search_closed_by(user.id)
1203-
embeds = self.format_log_embeds(entries, avatar_url=self.bot.guild.icon.url)
1203+
embeds = self.format_log_embeds(entries, avatar_url=self.bot.get_guild_icon(guild=ctx.guild))
12041204

12051205
if not embeds:
12061206
embed = discord.Embed(
@@ -1250,7 +1250,7 @@ async def logs_responded(self, ctx, *, user: User = None):
12501250

12511251
entries = await self.bot.api.get_responded_logs(user.id)
12521252

1253-
embeds = self.format_log_embeds(entries, avatar_url=self.bot.guild.icon.url)
1253+
embeds = self.format_log_embeds(entries, avatar_url=self.bot.get_guild_icon(guild=ctx.guild))
12541254

12551255
if not embeds:
12561256
embed = discord.Embed(
@@ -1275,7 +1275,7 @@ async def logs_search(self, ctx, limit: Optional[int] = None, *, query):
12751275

12761276
entries = await self.bot.api.search_by_text(query, limit)
12771277

1278-
embeds = self.format_log_embeds(entries, avatar_url=self.bot.guild.icon.url)
1278+
embeds = self.format_log_embeds(entries, avatar_url=self.bot.get_guild_icon(guild=ctx.guild))
12791279

12801280
if not embeds:
12811281
embed = discord.Embed(

cogs/utility.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,15 +1020,15 @@ async def alias(self, ctx, *, name: str.lower = None):
10201020
color=self.bot.error_color, description="You dont have any aliases at the moment."
10211021
)
10221022
embed.set_footer(text=f'Do "{self.bot.prefix}help alias" for more commands.')
1023-
embed.set_author(name="Aliases", icon_url=ctx.guild.icon.url)
1023+
embed.set_author(name="Aliases", icon_url=self.bot.get_guild_icon(guild=ctx.guild))
10241024
return await ctx.send(embed=embed)
10251025

10261026
embeds = []
10271027

10281028
for i, names in enumerate(zip_longest(*(iter(sorted(self.bot.aliases)),) * 15)):
10291029
description = utils.format_description(i, names)
10301030
embed = discord.Embed(color=self.bot.main_color, description=description)
1031-
embed.set_author(name="Command Aliases", icon_url=ctx.guild.icon.url)
1031+
embed.set_author(name="Command Aliases", icon_url=self.bot.get_guild_icon(guild=ctx.guild))
10321032
embeds.append(embed)
10331033

10341034
session = EmbedPaginatorSession(ctx, *embeds)
@@ -1611,7 +1611,9 @@ async def permissions_get(
16111611
for name, level in takewhile(lambda x: x is not None, items)
16121612
)
16131613
embed = discord.Embed(color=self.bot.main_color, description=description)
1614-
embed.set_author(name="Permission Overrides", icon_url=ctx.guild.icon.url)
1614+
embed.set_author(
1615+
name="Permission Overrides", icon_url=self.bot.get_guild_icon(guild=ctx.guild)
1616+
)
16151617
embeds.append(embed)
16161618

16171619
session = EmbedPaginatorSession(ctx, *embeds)

core/thread.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ async def send_recipient_genesis_message():
228228
else:
229229
footer = self.bot.config["thread_creation_footer"]
230230

231-
embed.set_footer(text=footer, icon_url=self.bot.guild.icon.url)
231+
embed.set_footer(text=footer, icon_url=self.bot.get_guild_icon(guild=self.bot.modmail_guild))
232232
embed.title = self.bot.config["thread_creation_title"]
233233

234234
if creator is None or creator == recipient:
@@ -521,7 +521,7 @@ async def _close(self, closer, silent=False, delete_channel=True, message=None,
521521

522522
embed.description = message
523523
footer = self.bot.config["thread_close_footer"]
524-
embed.set_footer(text=footer, icon_url=self.bot.guild.icon.url)
524+
embed.set_footer(text=footer, icon_url=self.bot.get_guild_icon(guild=self.bot.guild))
525525

526526
if not silent:
527527
for user in self.recipients:
@@ -957,7 +957,7 @@ async def send(
957957
name = tag
958958
avatar_url = self.bot.config["anon_avatar_url"]
959959
if avatar_url is None:
960-
avatar_url = self.bot.guild.icon.url
960+
avatar_url = self.bot.get_guild_icon(guild=self.bot.guild)
961961
embed.set_author(
962962
name=name,
963963
icon_url=avatar_url,

0 commit comments

Comments
 (0)