Skip to content

Instantly share code, notes, and snippets.

@NNTin
Created November 28, 2016 07:37
Show Gist options
  • Star 24 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save NNTin/2327df897a1de2b11711db1ff6d668bd to your computer and use it in GitHub Desktop.
Save NNTin/2327df897a1de2b11711db1ff6d668bd to your computer and use it in GitHub Desktop.
goes through a text channel's chat log and writes it to a file
import discord
import asyncio
client = discord.Client()
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
@client.event
async def on_message(message):
if message.content.startswith('record chat'):
with open('output.txt', 'a') as the_file:
async for log in client.logs_from(message.channel, limit=1000000000000000):
stringTime = log.timestamp.strftime("%Y-%m-%d %H:%M")
try:
author = log.author
except:
author = 'invalid'
message = str(log.content.encode("utf-8"))[2:-1]
template = '[{stringTime}] <{author}> {message}\n'
try:
the_file.write(template.format(stringTime=stringTime, author=author, message=message))
except:
author = log.author.discriminator
the_file.write(template.format(stringTime=stringTime, author=author, message=message))
print(template.format(stringTime=stringTime, author=author, message=message)[:-1])
elif message.content.startswith('!sleep'):
await asyncio.sleep(5)
await client.send_message(message.channel, 'Done sleeping')
client.run('<your token here>', bot=False)
@InfernoVortex
Copy link

How to find out a token to run the program? I'm fairly new to this so idk how to make it work.

@Davrial
Copy link

Davrial commented Jul 14, 2017

How do i use this? Just as a standalone .py document? Or do i put it somewhere in discord?

@JoMangee
Copy link

From reddit

You can let the program run from your user account. User token can be found in browser console localStorage.token.

@Monadic-Cat
Copy link

Discord would prefer you use a bot account to your user one. As I recall, it's in their Terms of Service.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment