Skip to content

Instantly share code, notes, and snippets.

@minid33
Created November 13, 2018 11:31
Show Gist options
  • Save minid33/f1473a6751d5fe9cf29523027fcda50e to your computer and use it in GitHub Desktop.
Save minid33/f1473a6751d5fe9cf29523027fcda50e to your computer and use it in GitHub Desktop.
When you want to invite a lot of users, make a bot, give it admin permissions and then run this.
import time
import requests
DISCORD_API_URL = 'https://discordapp.com/api/v6'
DISCORD_API_SECRET = 'Bot ...'
WELCOME_CHANNEL_ID = YOUR_CHANNEL_GOES_HERE
COHORT_SIZE = 1000
headers = {'Authorization': DISCORD_API_SECRET, 'Content-Type': 'application/json'}
def create_invite():
payload = {
'max_age': 0,
'max_uses': 1,
'temporary': False,
'unique': True
}
r = requests.post(f'{DISCORD_API_URL}/channels/{WELCOME_CHANNEL_ID}/invites', json=payload, headers=headers)
if r.status_code != 200:
print(r.status_code, r.json())
if r.status_code == 429:
time.sleep(r.json()['retry_after']/1000)
return r.json(), r.headers
def append_invite_file(invite_code):
with open ('invites.txt','a') as f:
f.write(f'https://discord.gg/{invite_code} \n')
def rate_limiter(headers):
wait_time = float(headers['X-RateLimit-Reset']) - time.time()
if int(headers['X-RateLimit-Remaining']) == 0:
if wait_time <=0:
wait_time = 0
print(f'Rate limit, Limit: { headers["X-RateLimit-Limit"] }, Remaining: {headers["X-RateLimit-Limit"]}, Reset: {wait_time}')
time.sleep(wait_time + 0.1)
def main():
for i in range(COHORT_SIZE):
invite, headers = create_invite()
append_invite_file(invite.get('code'))
print(i, invite.get('code'))
rate_limiter(headers)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment