Making arguments appear optional

pull/8/head
sgoudham 4 years ago
parent e8c66a5b2d
commit 6b644eb15c

@ -16,9 +16,16 @@ class Moderation(commands.Cog):
@command() @command()
@guild_only() @guild_only()
@has_guild_permissions(kick_members=True) @has_guild_permissions(kick_members=True)
async def kick(self, ctx, member: Member, *, reason="No Reason Given"): async def kick(self, ctx, member: Member, *, reason=None):
"""Kick Members from Server""" """Kick Members from Server"""
# Check if reason has been given
if reason:
reason = reason
# Set default reason to None
else:
reason = "No Reason Given"
await ctx.guild.kick(user=member, reason=reason) await ctx.guild.kick(user=member, reason=reason)
await ctx.send(f"{ctx.author.name} **kicked** {member.name}" await ctx.send(f"{ctx.author.name} **kicked** {member.name}"
@ -27,9 +34,16 @@ class Moderation(commands.Cog):
@command() @command()
@guild_only() @guild_only()
@has_guild_permissions(ban_members=True) @has_guild_permissions(ban_members=True)
async def ban(self, ctx, member: Member, *, reason="No Reason Given"): async def ban(self, ctx, member: Member, *, reason=None):
"""Ban Members from Server""" """Ban Members from Server"""
# Check if reason has been given
if reason:
reason = reason
# Set default reason to None
else:
reason = "No Reason Given"
await ctx.guild.ban(user=member, reason=reason) await ctx.guild.ban(user=member, reason=reason)
await ctx.send(f"{ctx.author.name} **banned** {member.name}" await ctx.send(f"{ctx.author.name} **banned** {member.name}"
@ -38,9 +52,16 @@ class Moderation(commands.Cog):
@command() @command()
@guild_only() @guild_only()
@has_guild_permissions(ban_members=True) @has_guild_permissions(ban_members=True)
async def unban(self, ctx, member: int, *, reason="No Reason Given"): async def unban(self, ctx, member: int, *, reason=None):
"""Unban Member from Server""" """Unban Member from Server"""
# Check if reason has been given
if reason:
reason = reason
# Set default reason to None
else:
reason = "No Reason Given"
member = await self.bot.fetch_user(member) member = await self.bot.fetch_user(member)
await ctx.guild.unban(member, reason=reason) await ctx.guild.unban(member, reason=reason)
@ -50,12 +71,14 @@ class Moderation(commands.Cog):
@command() @command()
@guild_only() @guild_only()
@has_guild_permissions(manage_messages=True) @has_guild_permissions(manage_messages=True)
async def purge(self, ctx, amount=100): async def purge(self, ctx, amount: int):
"""Purge Messages from Channel""" """Purge Messages from Channel"""
if not amount:
amount = 100
if amount > 100: if amount > 100:
await ctx.send("Sorry! You can only purge up to **100** messages at a time!") await ctx.send("Sorry! You can only purge up to **100** messages at a time!")
else: elif amount <= 100:
channel = ctx.message.channel channel = ctx.message.channel
messages = [] messages = []
@ -63,7 +86,7 @@ class Moderation(commands.Cog):
messages.append(message) messages.append(message)
await channel.delete_messages(messages) await channel.delete_messages(messages)
await ctx.send(f"{ctx.author.mention} {amount} messages deleted!") msg = await ctx.send(f"{ctx.author.mention} {amount} messages deleted!")
def setup(bot): def setup(bot):

Loading…
Cancel
Save