Rifat Azad commited on
Commit
7241c03
·
1 Parent(s): 7f5c15c
Files changed (1) hide show
  1. pydvpl_bot.py +19 -27
pydvpl_bot.py CHANGED
@@ -793,30 +793,25 @@ async def list(ctx, list_type):
793
 
794
  @bot.hybrid_command(help="Kick a member from the server.")
795
  async def kick(ctx, member: discord.Member, *, reason=None):
796
- # Check if the author is owner of the guild to use this command
797
  if ctx.author.guild_permissions.kick_members or ctx.author == ctx.guild.owner:
798
 
799
  if ctx.author.top_role > member.top_role:
800
 
801
- # Send a DM to the kicked member
802
- dm_message = f"You have been kicked from the server `{ctx.guild.name}`"
803
- if reason:
804
- dm_message += f" for the following reason: `{reason}`"
805
  try:
 
 
 
806
  await member.send(dm_message)
807
  except discord.Forbidden:
808
- await ctx.send(f"Failed to send DM to `{member}` for kick.")
809
 
810
  # Kick the member from the server
811
- try:
812
- await member.kick(reason=reason)
813
- await ctx.send(f"`{member}` has been kicked from the server. Reason: `{reason}`")
814
- except discord.Forbidden:
815
- await ctx.send("I don't have permission to kick this member.")
816
-
817
  else:
818
  await ctx.send("You do not have permission to kick this member.")
819
-
820
  else:
821
  await ctx.send("You do not have permission to use this command.")
822
 
@@ -826,34 +821,31 @@ async def kick(ctx, member: discord.Member, *, reason=None):
826
 
827
  @bot.hybrid_command(help="Ban a member from the server.")
828
  async def ban(ctx, member: discord.Member, *, reason=None):
829
- # Check if the author is owner of the guild to use this command
830
  if ctx.author.guild_permissions.ban_members or ctx.author == ctx.guild.owner:
831
 
832
  if ctx.author.top_role > member.top_role:
833
 
834
- # Send a DM to the banned member
835
- dm_message = f"You have been banned from the server `{ctx.guild.name}`"
836
- if reason:
837
- dm_message += f" for the following reason: `{reason}`"
838
  try:
 
 
 
839
  await member.send(dm_message)
840
  except discord.Forbidden:
841
- await ctx.send(f"Failed to send DM to `{member}` for ban.")
842
-
843
- # Ban the member from the server
844
- try:
845
- await member.ban(reason=reason)
846
- await ctx.send(f"`{member}` has been banned from the server. Reason: `{reason}`")
847
- except discord.Forbidden:
848
- await ctx.send("I don't have permission to ban this member.")
849
 
 
 
 
850
  else:
851
  await ctx.send("You do not have permission to ban this member.")
852
-
853
  else:
854
  await ctx.send("You do not have permission to use this command.")
855
 
856
 
 
 
857
  # FUNCTION ------------------------------------------------------ SPLIT
858
 
859
 
 
793
 
794
  @bot.hybrid_command(help="Kick a member from the server.")
795
  async def kick(ctx, member: discord.Member, *, reason=None):
 
796
  if ctx.author.guild_permissions.kick_members or ctx.author == ctx.guild.owner:
797
 
798
  if ctx.author.top_role > member.top_role:
799
 
800
+ # Attempt to send a DM to the kicked member
 
 
 
801
  try:
802
+ dm_message = f"You have been kicked from the server `{ctx.guild.name}`"
803
+ if reason:
804
+ dm_message += f" for the following reason: `{reason}`"
805
  await member.send(dm_message)
806
  except discord.Forbidden:
807
+ await ctx.send(f"Failed to send a direct message to {member}.")
808
 
809
  # Kick the member from the server
810
+ await member.kick(reason=reason)
811
+ await ctx.send(f"{member} has been kicked from the server.")
 
 
 
 
812
  else:
813
  await ctx.send("You do not have permission to kick this member.")
814
+
815
  else:
816
  await ctx.send("You do not have permission to use this command.")
817
 
 
821
 
822
  @bot.hybrid_command(help="Ban a member from the server.")
823
  async def ban(ctx, member: discord.Member, *, reason=None):
 
824
  if ctx.author.guild_permissions.ban_members or ctx.author == ctx.guild.owner:
825
 
826
  if ctx.author.top_role > member.top_role:
827
 
828
+ # Attempt to send a DM to the banned member
 
 
 
829
  try:
830
+ dm_message = f"You have been banned from the server `{ctx.guild.name}`"
831
+ if reason:
832
+ dm_message += f" for the following reason: `{reason}`"
833
  await member.send(dm_message)
834
  except discord.Forbidden:
835
+ await ctx.send(f"Failed to send a direct message to {member}.")
 
 
 
 
 
 
 
836
 
837
+ # Ban the member from the server
838
+ await member.ban(reason=reason)
839
+ await ctx.send(f"{member} has been banned from the server.")
840
  else:
841
  await ctx.send("You do not have permission to ban this member.")
842
+
843
  else:
844
  await ctx.send("You do not have permission to use this command.")
845
 
846
 
847
+
848
+
849
  # FUNCTION ------------------------------------------------------ SPLIT
850
 
851