Quart-Nextcord

Discord OAuth2 extension for Quart.


Keywords
aiohttp, discord, discord-bot, discordpy, flask, nextcord, python, python3, quart
License
MIT
Install
pip install Quart-Nextcord==2.1.6a1

Documentation

Quart-Nextcord

PyPI Read the Docs

Discord OAuth2 extension for Quart.

NO SUPPORT & UPDATES

[!] This library will not get any updates in the future. [!]

Installation

To install current latest release you can use following command:

python3 -m pip install Quart-Nextcord

To install the current dev version you can use followering command:

python3 - m pip install git+https://github.com/InvalidLenni/Quart-Nextcord/tree/dev

Basic Example

from quart import Quart, redirect, url_for
from quart_nextcord import DiscordOAuth2Session, requires_authorization, Unauthorized

app = Quart(__name__)

app.secret_key = b"random bytes representing quart secret key"

app.config["DISCORD_CLIENT_ID"] = 490732332240863233  # Discord client ID.
app.config["DISCORD_CLIENT_SECRET"] = ""  # Discord client secret.
app.config["DISCORD_REDIRECT_URI"] = ""  # URL to your callback endpoint.
app.config["DISCORD_BOT_TOKEN"] = ""  # Required to access BOT resources.

nextcord = DiscordOAuth2Session(app)


@app.route("/login/")
async def login():
    return await nextcord.create_session()


@app.route("/callback/")
async def callback():
    await nextcord.callback()
    return redirect(url_for(".me"))


@app.errorhandler(Unauthorized)
async def redirect_unauthorized(e):
    return redirect(url_for("login"))


@app.route("/me/")
@requires_authorization
async def me():
    user = await nextcord.fetch_user()
    return f"""
    <html>
        <head>
            <title>{user.name}</title>
        </head>
        <body>
            <img src='{user.avatar_url}' />
        </body>
    </html>"""


if __name__ == "__main__":
    app.run()

For an example to the working application, check test_app.py

Requirements

  • Quart
  • Async-OAuthlib
  • cachetools
  • nextcord

Documentation

Head over to documentation for full API reference.