Skip to content

Instantly share code, notes, and snippets.

@NNTin
Created November 28, 2016 07:37
Show Gist options
  • 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)
@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