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