The Python OAuth2 and Discord Bot Commands for Flask applications.
Project description
Flask-Discord-Extended
The Python OAuth2 and Discord Bot Commands for Flask applications.
Installation
To install current latest release you can use following command:
python3 -m pip install Flask-Discord-Extended
Code Example
from flask_discord_extended import FlaskDiscord
from flask import Flask
import os
app = Flask(__name__)
os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "true"
app.config["DISCORD_CLIENT_ID"] = "" # Discord Client Id
app.config["DISCORD_CLIENT_SECRET"] = "" # Discord Client Secret
app.config["DISCORD_OAUTH"] = True # Set True if you need Oauth feature
app.config["DISCORD_OAUTH_SCOPE"] = ['identify'] # Scopes for Oauth
app.config["DISCORD_OAUTH_REDIRECT_URI"] = "" # Redirect Uri for Oauth
app.config["DISCORD_AUTHORIZATION"] = "" # Bot aothorization token
Discord = FlaskDiscord(app)
@app.route('/')
def index():
return """
<form action = "/discord-login" method = "GET">
<button type = "submit" style = "padding: 15px; background:rgb(88, 101, 242); cursor: pointer; color: white; border: 0px; border-radius:5px">LogIn With Discord</button>
<form>
"""
@app.route('/discord-login')
def login():
# Redirects to Discord login
return Discord.Oauth.redirect_login()
@app.route('/callback')
def test():
user = Discord.Oauth.callback()
"""
Each function from the Utilities returns an json response object
The bot whose authorization code is set to the app needs to be in the same server
with the user
"""
Discord.Utilities.add_role(guild="GUILD_ID", user_id=user["id"], role="ROLE_ID")
Discord.Utilities.remove_role(guild="GUILD_ID", user_id=user["id"], role="997877802265235586")
Discord.Utilities.get_guild_member_data(guild="GUILD_ID", user_id=user["id"])
Discord.Utilities.set_nickname(guild="GUILD_ID", user_id=user["id"], nickname="Any nickname")
Discord.Utilities.send_dm(user_id=user["id"], content="Content")
return user
if __name__ == "__main__":
app.run(debug=True)
Requirements
- Flask
- requests_oauthlib
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file Flask-Discord-Extended-0.0.6.tar.gz
.
File metadata
- Download URL: Flask-Discord-Extended-0.0.6.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a433e429bc8512f64a6e485028ae03835b1e4a5121b546d1280f811cd30be19e |
|
MD5 | 1afda3c2331113ed34080417916bd489 |
|
BLAKE2b-256 | b22d12529073948e1d2b88a89cb7699eea60a2c6d52a46ac06baeefd34e671ea |