xxxxxxxxxx
# unBan command
@bot.command()
@commands.has_permissions(ban_members=True)
async def unban(ctx : discord.Member, id: int):
user = await bot.fetch_user(id)
#=================================
guild = bot.get_guild(920733512124989461) # Get server id to make action
channel = guild.get_channel(974470211891773440) # sent to log channel
now = datetime.now()
current_time = now.strftime("%H:%M")
#==================================
# Private message embed
emDm = discord.Embed(title="Moderation System", description=f"**Your banned has been
removed by {ctx.author}**", color=0xe54b4b)
#===================================
# log unbanned embed
emUnban = discord.Embed(title="Moderation System", description=f"{user} has been
pardoned", color=0xFFB433)
try:
await ctx.guild.unban(user)
await ctx.reply(f"> **Ban has been removed from {user}**", mention_author=False)
await channel.send(embed=emUnban) # sent to log channel
await user.send(emDm) # Sent dm embed
print(f"{current_time}: {user} has been unban by {ctx.author}\n ")
except discord.Forbidden:
await ctx.send(f"I don't have permission to make this action")
# unBan error
@unban.error
async def unban_error(ctx, error):
if isinstance(error, commands.MissingPermissions):
await ctx.send("> **You can't make this action**")
now = datetime.now()
current_time = now.strftime("%H:%M")
print(f"{current_time}: {ctx.author} tried to unban\nUser id : {ctx.author.id}\n")
time.sleep(1)
await ctx.channel.purge(limit=1)
xxxxxxxxxx
@client.command()
async def unban(ctx, *, member):
banned_users = await ctx.guild.bans()
member_name, member_discriminator = member.split('#')
for ban_entry in banned_users:
user = ban_entry.user
if (user.name, user.discriminator) == (member_name, member_discriminator):
await ctx.guild.unban(user)
await ctx.channel.send(f"Unbanned: {user.mention}")
xxxxxxxxxx
@client.command()
@commands.has_permissions(ban_members=True)
async def unban(ctx, *, member):
banned_users = await ctx.guild.bans()
member_name, member_discriminator = member.split('#')
for ban_entry in banned_users:
user = ban_entry.user
if (user.name, user.discriminator) == (member_name,
member_discriminator):
await ctx.guild.unban(user)
await ctx.send(f'Unbanned {user.mention}')
return
xxxxxxxxxx
@client.command()
async def unban(ctx, *,member):
banned_user = await ctx.guild.bans()
member_name, member_discriminator = member.split('#')
for ban_entry in banned_users:
user = ban_entry.user
if (user.name, user.discriminator) == (member_name, member_discriminator):
await ctx.guild.unban(user)
await ctx.send(f'Unbanned {user.mention}')
xxxxxxxxxx
@client.command()
@commands.has_role(1234567890) # Role ID
@commands.cooldown(1,15, commands.BucketType.user)
async def unban(ctx, member:discord.User, *, reason=None):
if reason == None:
reason = f"No Reason Provided"
await ctx.guild.unban(member, reason=reason)
await ctx.send(f"{member.mention} has been **unbanned**", delete_after=15)
embed = discord.Embed(title="Unban Log", description=f"{member.mention} has been **unbanned** by {ctx.author.mention}\n\nReason: `{reason}`\n\nUnbanned from: `{ctx.guild.name}`", color=0x1355ed)
embed.add_field(name="User", value=f"{member}", inline=True)
embed.add_field(name="UserID", value=f"{member.id}", inline=True)
embed.add_field(name="Moderator", value=f"{ctx.author}", inline=True)
embed.set_footer(text=f"Unban log - Banned user: {member.name}")
embed.set_thumbnail(url=member.avatar_url)
embed.timestamp = datetime.datetime.utcnow()
logchannel = client.get_channel(988416086217203732)
await logchannel.send(embed=embed)
await ctx.message.delete()
print(f"Sucsessfully unbanned {member.name}")