0

I am creating a script that logs onto Discord by using a token.

This is my code:

import requests

headers = {
    'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36'
}


with requests.Session() as s:
    url = 'https://discord.com/login'
    r = s.get(url, headers=headers)
    print(r.content)

In order to actually login using a token I need to run the following code in the browser's developer console:

function login(token) {
setInterval(() => {
document.body.appendChild(document.createElement `iframe`).contentWindow.localStorage.token = `"${token}"`
}, 50);
setTimeout(() => {
location.reload();
}, 2500);
}

login ("[enter your token here]")

I know that this is possible in selenium but I really need to do it in requests.

3
  • I don't think you can use the dev-console because there's no browser associated with a request. IF you're willing/able to use alternative approaches there should be some in here and at the docs for complicated POST requests Commented Feb 18, 2021 at 16:25
  • Oh Thanks! But do you know if it's possible in any other language? It has to use the console so it can log in using a discord token. I found this thread which works on selenium. But I really need something faster since selenium takes way too long. Do you know of any alternatives to requests. That uses the developer console and isn't as slow as selenium? Commented Feb 18, 2021 at 16:41
  • I don't, but if you can use JavaScript that's probably your best bet. Commented Feb 20, 2021 at 2:39

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.