def oauth_session(request, state=None, token=None):
if settings.DISCORD_REDIRECT_URI is not None:<EOL><INDENT>redirect_uri = settings.DISCORD_REDIRECT_URI<EOL><DEDENT>else:<EOL><INDENT>redirect_uri = request.build_absolute_uri(<EOL>reverse('<STR_LIT>'))<EOL><DEDENT>scope = (['<STR_LIT:email>', '<STR_LIT>'] if settings.DISCORD_EMAIL_SCOPE<EOL>else ['<STR_LIT>', '<STR_LIT>'])<EOL>return OAuth2Session(settings.DISCORD_CLIENT_ID,<EOL>redirect_uri=redirect_uri,<EOL>scope=scope,<EOL>token=token,<EOL>state=state)<EOL>
Constructs the OAuth2 session object.