Skip to content

Instantly share code, notes, and snippets.

@NNTin
CreatedNovember 28, 2016 07:37
    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

    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