Skip to content

Commit

Permalink
[RoleTools] Add support for assigning roles to thread members
Browse files Browse the repository at this point in the history
  • Loading branch information
TrustyJAID committed Oct 5, 2024
1 parent 10433f3 commit e459085
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
13 changes: 11 additions & 2 deletions roletools/roletools.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ async def giverole(
self,
ctx: Context,
role: RoleHierarchyConverter,
*who: Union[discord.Role, discord.TextChannel, discord.Member, str],
*who: Union[discord.Role, discord.TextChannel, discord.Thread, discord.Member, str],
) -> None:
"""
Gives a role to designated members.
Expand Down Expand Up @@ -383,7 +383,16 @@ async def giverole(
async with ctx.typing():
members = []
for entity in who:
if isinstance(entity, discord.TextChannel) or isinstance(entity, discord.Role):
if isinstance(entity, discord.Thread):
try:
thread_members = await entity.fetch_members()
for m in thread_members:
if mem := ctx.guild.get_member(m.id):
members.append(mem)
except Exception:
log.error("Could not find members of thread in %s", entity)

elif isinstance(entity, discord.TextChannel) or isinstance(entity, discord.Role):
members += entity.members
elif isinstance(entity, discord.Member):
members.append(entity)
Expand Down
6 changes: 5 additions & 1 deletion roletools/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,11 @@ async def create_select_menu(
for item in replacement_view.children:
if item.custom_id == custom_id:
replacement_view.remove_item(item)
replacement_view.add_item(select_menus)
try:
replacement_view.add_item(select_menus)
except ValueError:
log.error("Error editing old menu on Select Menu %s", custom_id)
continue

select_menus.update_options(ctx.guild)
view = RoleToolsView(self, timeout=180.0)
Expand Down

0 comments on commit e459085

Please sign in to comment.