Guest User

Untitled

a guest
Feb 25th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. #!/usr/bin/python3
  2. '''
  3. Author: Cody (@now)
  4.  
  5. This Python script will log chat in Discord chatrooms.
  6. and relay logs to a private Discord channel and save
  7. them to a text file. This is useful for spying on people.
  8. '''
  9. import asyncio
  10. import datetime
  11. import discord
  12. import json
  13. import re
  14. import time
  15.  
  16. c = discord.Client()
  17.  
  18. # Your Discord token
  19. token = "your_token_goes_here"
  20.  
  21. @c.event
  22. async def on_ready():
  23. welcome = "Logged in as {0.name} - {0.id}\n".format(c.user)
  24. # Make the log bot appear offline.
  25. await c.change_presence(status=discord.Status.invisible)
  26. print(welcome)
  27.  
  28. @c.event
  29. async def on_message(message):
  30. # Replace '412905214533838722' with the Discord channel ID you want to log.
  31. if message.channel.id == "412905214533838722":
  32. # Formatting the log: User-ID <Username#0001> Message
  33. msg = "**{0.author.id} <{0.author}>** {0.content}".format(message)
  34.  
  35. # Plaintext formatting for writing the log to the file.
  36. # Also adding timestamp for this one.
  37. now = datetime.datetime.now()
  38. timestamp = now.strftime("%Y-%m-%d %H:%M:%S")
  39. tzone = time.strftime("%Z", time.gmtime())
  40. log = "{0.author.id} {1} {2} <{0.author}> {0.content}".format(message, timestamp, tzone)
  41. if message.attachments:
  42. # If someone posted a picture, we're going to get the url for it
  43. # and append it to our log string.
  44. img = message.attachments[0]['url']
  45. msg += " {}".format(img)
  46. log += " {}".format(img)
  47.  
  48. # Replace '412905216279831337' with the Dicord channel ID you want to relay logs to.
  49. await c.send_message(c.get_channel("412905216279831337"), msg)
  50.  
  51. # Writing the log to a text file.
  52. print(log, file=open("name_of_server_or_channel.txt", "a"))
  53.  
  54. c.run(token, bot=False)
Add Comment
Please, Sign In to add comment