![]() ![]() Bot ): def _init_ ( self, * args, ** kwargs ): super (). Import discord from discord.ext import commands, ipc class MyBot ( commands. In the same folder where main.py is located, create a new directory and file templates/home.html and paste the code below. If you notice in the code above, we used a file home.html this is the page that the will handle the authentication button. If you are building a real-world project, you will need to make sure to keep those credentials secure. Remember the credentials I told you to take note of earlier? You will need to input them in the code above. callback () except Exception : pass return redirect ( url_for ( "dashboard" )) #dashboard function will be created later in the a route ( "/callback" ) async def callback (): try : await discord. create_session () # handles session creation for app. route ( "/login" ) async def login (): return await discord. ![]() route ( "/" ) async def home (): return await render_template ( "home.html", authorized = await discord. config = "" # URL to your callback endpoint.ĭiscord = DiscordOAuth2Session ( app ) #handle session for app. config = "dfp9GSgUHqvIMBSEIsrG9DW1XMnJskhl" # Discord client secret.Īpp. environ = "1" # this is required because OAuth 2 utilizes https.Īpp = Quart ( _name_ ) app. Now, let’s install the dependencies with the following command.įrom quart import Quart, render_template, redirect, url_for from quart_discord import DiscordOAuth2Session import os os. Open the URL on the browser, select the server you want to connect the bot to it, and submit all the redirects. This URL will be used to connect the bot to the server. On the OAuth2 dropdown, click the URL Generator tab and select the scope that you see on the image below. Also, take note of the CLIENT ID and CLIENT SECRET because we will need them in the code. The URL we will be using for the redirect is. This is where you will add the URL that will handle the redirect after authentication. Next, click the OAuth2 dropdown and then click the Add Redirect button. ![]() Then, fill in the “Name” field and submit. To do this, go to the Discord developer portal, and * **on the Discord developer portal page, click the “ New Application*” button in the top right corner. You may not want everyone to be able to access that page, so you can use the OAuth2 system provided by Discord. Later in this article, we will be building something like a dashboard where you can see all the servers that have your bot attached to it.
0 Comments
Leave a Reply. |