Skip to content

Commit

Permalink
chore: Fix typehint for MemberOrUser
Browse files Browse the repository at this point in the history
  • Loading branch information
null2264 committed Aug 27, 2023
1 parent 1ef2848 commit 348b3f5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
20 changes: 12 additions & 8 deletions src/zibot/core/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,19 @@ async def convert(self, ctx: Context, argument):
return entity[0]


class MemberOrUser(commands.Converter):
async def convert(self, ctx: Context, argument):
try:
return await commands.MemberConverter().convert(ctx, argument)
except commands.MemberNotFound:
if TYPE_CHECKING:
MemberOrUser = discord.User | discord.Member
else:

class MemberOrUser(commands.Converter):
async def convert(self, ctx: Context, argument):
try:
return await commands.UserConverter().convert(ctx, argument)
except commands.UserNotFound:
return None
return await commands.MemberConverter().convert(ctx, argument)
except commands.MemberNotFound:
try:
return await commands.UserConverter().convert(ctx, argument)
except commands.UserNotFound:
return None


def checkHierarchy(ctx: Context, user, action: str = None) -> Optional[str]:
Expand Down
2 changes: 1 addition & 1 deletion src/zibot/exts/mod/mod.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ async def unmute(self, ctx, member: MemberOrUser, *, reason: str = "No reason"):
if not mutedRoleId:
raise MissingMuteRole(ctx.clean_prefix) from None

if not member._roles.has(mutedRoleId):
if isinstance(member, discord.Member) and not member._roles.has(mutedRoleId):
return await ctx.error(f"{member.mention} is not muted!")

await self.doModeration(ctx, member, None, action="unmute", reason=reason, mutedRoleId=mutedRoleId)
Expand Down

0 comments on commit 348b3f5

Please sign in to comment.