CreatedNovember 28, 2016 07:37
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) |
InfernoVortex commented Jul 9, 2017
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 commented May 21, 2018
From reddit
You can let the program run from your user account. User token can be found in browser console localStorage.token.
Monadic-Cat commented Oct 17, 2019
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 to find out a token to run the program? I'm fairly new to this so idk how to make it work.