Skip to content

Commit 28ea9e3

Browse files
Finalise
1 parent 360390d commit 28ea9e3

1 file changed

Lines changed: 19 additions & 7 deletions

File tree

cogs/thread_friends.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,15 @@ async def add_user_or_role_with_ping(self, user_or_role: discord.Member | discor
7777
if isinstance(user_or_role, discord.Role):
7878
member: discord.Member
7979
for member in user_or_role.members:
80-
await thread.add_user(member)
80+
try:
81+
await thread.add_user(member)
82+
except discord.NotFound:
83+
logger.debug(
84+
"User: %s has blocked the bot and "
85+
"therefore could not be added to thread: %s.",
86+
member,
87+
thread
88+
)
8189
return
8290

8391
logger.debug("User or role: %s is not a valid type.", user_or_role)
@@ -95,7 +103,10 @@ async def on_thread_create(self, thread: discord.Thread) -> None:
95103

96104
if "committee" in thread.parent.category.name.lower():
97105
await self.add_user_or_role_silently(user_or_role=committee_role, thread=thread)
98-
await self.add_user_or_role_silently(user_or_role=committee_elect_role, thread=thread)
106+
await self.add_user_or_role_silently(
107+
user_or_role=committee_elect_role,
108+
thread=thread,
109+
)
99110

100111
@discord.slash_command( # type: ignore[no-untyped-call, misc]
101112
name="add_users_to_thread",
@@ -116,8 +127,8 @@ async def on_thread_create(self, thread: discord.Thread) -> None:
116127
required=False,
117128
parameter_name="silent",
118129
)
119-
async def add_users_to_thread(self, ctx: "TeXBotApplicationContext", user_or_role: str, silent: bool) -> None: # noqa: E501
120-
"""Method for adding users to a thread."""
130+
async def add_users_to_thread(self, ctx: "TeXBotApplicationContext", user_or_role: str, silent: bool) -> None: # noqa: E501, FBT001
131+
"""Add users or roles to a thread."""
121132
main_guild: discord.Guild = ctx.bot.main_guild
122133

123134
if not isinstance(ctx.channel, discord.Thread):
@@ -132,7 +143,7 @@ async def add_users_to_thread(self, ctx: "TeXBotApplicationContext", user_or_rol
132143
try:
133144
user_object: discord.Member = await self.bot.get_member_from_str_id(user_or_role)
134145
except ValueError:
135-
logger.debug("User ID: %s is not a valid user ID.", user_or_role)
146+
pass
136147
else:
137148
if silent:
138149
await self.add_user_or_role_silently(user_object, thread)
@@ -147,14 +158,15 @@ async def add_users_to_thread(self, ctx: "TeXBotApplicationContext", user_or_rol
147158
try:
148159
role_id: int = int(user_or_role)
149160
except ValueError:
150-
logger.debug("Role ID: %s is not a valid role ID.", user_or_role)
161+
logger.debug("Role or User ID: %s is not a valid ID.", user_or_role)
162+
await ctx.respond(content=f"The role or user: {user_or_role} is not valid.")
151163
return
152164

153165
role_object: discord.Role | None = discord.utils.get(main_guild.roles, id=role_id)
154166
if role_object is None:
155167
await self.command_send_error(
156168
ctx=ctx,
157-
message="The role you entered does not exist or the user could not be found.",
169+
message=f"The role or user: <@{role_id}> is not valid or couldn't be found.",
158170
)
159171
return
160172

0 commit comments

Comments
 (0)