Created
November 28, 2016 07:37
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
From reddit
You can let the program run from your user account. User token can be found in browser console localStorage.token.
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
How do i use this? Just as a standalone .py document? Or do i put it somewhere in discord?