Guest User

Truce#0001

a guest
Feb 24th, 2019
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.86 KB | None | 0 0
  1. import discord
  2. import time
  3. from discord.ext import commands
  4.  
  5. # Intializes bot and it's options.
  6. token = 'YourToken'
  7. prefix = '*'
  8. bot = commands.Bot(command_prefix=prefix, case_insensitive=True, self_bot=True)
  9.  
  10. @bot.event
  11. async def on_ready():
  12.     print(f"A Permenant truce is not viable... 3aK bot is ready, prefix is {prefix}")
  13.  
  14. @bot.command(aliases=['delmsg', 'deletemessage'])
  15. async def deletemsg(ctx, userid):
  16.     user_id = int(userid)  # User id of the other user in the dm channel
  17.     user_channel = bot.get_user(int(user_id))  # The channel of that user
  18.  
  19.     message_count = 0  # Variable for how many messages have been deleted
  20.     time_log = time.strftime("year%Y-month%m-day%d-hour%H-min%M-sec%S")  # Time log
  21.     file_name = f"{user_channel.name}#{user_channel.discriminator}-log-{time_log}"  # File Name
  22.     file = open(f"{file_name}.txt", "w+", encoding="utf-8") # Open up the file with the file_name variable
  23.     print(f"Log file was succesfully created, name of log file is == {file_name}")  # Print out when the log has been created
  24.  
  25.     async for message in user_channel.history(limit=None):
  26.         if message.author == ctx.message.author:  # If you're the author of the message
  27.             if message.type is discord.MessageType.default:  # If the message is a normal message
  28.                 file.write(f"{ctx.message.author}:{message.created_at}:{message.content}" + "\n")
  29.                 print(f'{message_count} messages deleted!', end='\r')  # Overwrites last print with new message count
  30.                 message_count+=1  # Adds onto how many messages have been deleted
  31.                 await message.delete()  # Deletes the message
  32.     else:
  33.         print(f"finished deleting messages with user: {user_channel.name}#{user_channel.discriminator}")
  34.         return file.close()  # Saves all the deleted messages now
  35.  
  36. bot.run(token, bot=False)
Advertisement
Add Comment
Please, Sign In to add comment