Skip to content

Commit

Permalink
error handing in mute cogs
Browse files Browse the repository at this point in the history
  • Loading branch information
Xarlos89 committed Dec 21, 2024
1 parent f19997e commit 9240b6a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/bot/cogs/moderation/admin_kick.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ async def kick_member(self, ctx, target: discord.Member, reason):
await ctx.channel.send(embed=embed_info("You cant kick a bot."))

@kick_member.error
async def ban_error(self, ctx, error):
async def kick_error(self, ctx, error):
if isinstance(error, commands.MemberNotFound):
await ctx.channel.send(embed=embed_info(
f"User was not found, please check the name and use a mention."))
Expand Down
20 changes: 13 additions & 7 deletions src/bot/cogs/moderation/admin_mute.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
logger = logging.getLogger(__name__)


def embed_cant_do_that(message):
def embed_info(message):
"""
Embedding for things you cant do.
Embedding for generl things
"""
embed = discord.Embed(
title=''
Expand Down Expand Up @@ -44,19 +44,25 @@ async def mute_member(self, ctx, target: discord.Member, time, reason):
if not target.guild_permissions.administrator:
# Message the user, informing them of their fate
await target.send(f"## You were muted by {ctx.author.name}.\n" f"**Time:** {time} minutes")
# Then we do the ban
# Then we do the mute
time_in_mins = datetime.utcnow() + timedelta(minutes=int(time))
await target.timeout(time_in_mins, reason=None)
logger.info("{%s} muted {%s} for {%s} minutes. Reason: {%s}", ctx.author.name, target.name, time, reason)
# Then we publicly announce what happened.
await ctx.respond(
embed=embed_cant_do_that(f"**{ctx.author.name}** muted **{target.name}** for {time} minutes" f"\n**Reason:** {reason}")
await ctx.channel.send(
embed=embed_info(f"**{ctx.author.name}** muted **{target.name}** for {time} minutes" f"\n**Reason:** {reason}")
)

else:
await ctx.respond(embed=embed_cant_do_that("You can't mute an Admin."), ephemeral=True)
await ctx.channel.send(embed=embed_info("You can't mute an Admin."))
else:
await ctx.respond(embed=embed_cant_do_that("You cant mute a bot."), ephemeral=True)
await ctx.channel.send(embed=embed_info("You cant mute a bot."))

@mute_member.error
async def mute_error(self, ctx, error):
if isinstance(error, commands.MemberNotFound):
await ctx.channel.send(embed=embed_info(
f"User was not found, please check the name and use a mention."))


async def setup(bot) -> None:
Expand Down

0 comments on commit 9240b6a

Please sign in to comment.