Skip to content

Instantly share code, notes, and snippets.

@timelf123
Forked from ErikBoesen/getnames.py
Created January 23, 2018 04:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save timelf123/0b5690d62dca0859d6bc63c82a7b0881 to your computer and use it in GitHub Desktop.
Save timelf123/0b5690d62dca0859d6bc63c82a7b0881 to your computer and use it in GitHub Desktop.
Given a file ./tokens.txt containing many Discord bot tokens, this script will attempt login with each, and write valid tokens (plus their names and how many servers they're in) to ./valid.csv.
import discord
import asyncio
class Bot(discord.Client):
def __init__(self, token):
super().__init__()
self.token = token
print('%s->' % token, end='')
async def on_ready(self):
"""Run when the bot is ready."""
print('%s#%s' % (self.user.name, len(self.servers)))
with open('valid.csv', 'a+') as f:
f.write('%s,%s,%s\n' % (self.token, self.user.name, len(self.servers)))
await self.logout()
if __name__ == '__main__':
with open('tokens.txt') as f:
tokens = [token for token in f.read().split('\n') if token]
with open('valid.csv') as f:
f.write('token,name,servers')
loop = asyncio.get_event_loop()
bots = []
for token in tokens:
bots.append(Bot(token))
try:
loop.run_until_complete(bots[-1].start(token))
except discord.errors.LoginFailure:
print('BAD TOKEN')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment