45
loading...
This website collects cookies to deliver better user experience
import requests
API_ENDPOINT = 'https://discord.com/api/v8'
CLIENT_ID = ''
CLIENT_SECRET = ''
REDIRECT_URI = "https://google.com"
REDIRECT_URI
too. This is the URI that we will be using to get the code from our user, that we then can use to exchange it for an actual access_token. But we have to add this URI in our Developer Portal. The URI does not matter, it can be anything. But we have to allow it.def exchange_code(code):
data = {
'client_id': CLIENT_ID,
'client_secret': CLIENT_SECRET,
'grant_type': 'authorization_code',
'code': code,
'redirect_uri': REDIRECT_URI
}
headers = {
'Content-Type': 'application/x-www-form-urlencoded'
}
r = requests.post('%s/oauth2/token' % API_ENDPOINT, data=data, headers=headers)
r.raise_for_status()
return r.json()
def add_to_guild(access_token, userID, guildID):
url = f"{API_ENDPOINT}/guilds/{guildID}/members/{userID}"
botToken = "ODcyMjMyMjQ5ODYzNTkzOTk0.YQm3lQ.yB3pFepBcy7K1gQVrBxNfYf_Bdk"
data = {
"access_token" : access_token,
}
headers = {
"Authorization" : f"Bot {botToken}",
'Content-Type': 'application/json'
}
response = requests.put(url=url, headers=headers, json=data)
print(response.text)
code = exchange_code('')['access_token']
add_to_guild(code, 'USER_ID', 'GUILD_ID')
exchange_code
function? Well this is the part where the user has to go to the authorize link and authorize our application.https://discord.com/oauth2/authorize?response_type=code&client_id=157730590492196864&scope=identify+guilds.join&state=15773059ghq9183habn&redirect_uri=https%3A%2F%2Fgoogle.com&prompt=consent
exchange_code
function.https://discord.com/oauth2/authorize?client_id=123456789012345678&scope=bot+applications.commands