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. Discord account and about five servers created.With that said, we will have to use a version of Flask that handle asynchronous requests perfectly Quart. When working with Discord, a lot of functionality will need to be handled asynchronously because Discord uses WebSockets to build real-time communication between the Discord API and the application. We will begin by explaining how to set up Discord OAuth2 for authentication, followed by building a simple discord bot and attaching it to some servers, and finally, displaying the servers where the bot is attached on the frontend. In this article, you will learn how to use some features provided by Discord API. Discord provides a way to section different groups of people with Server/Guild. Ruby (178) Honeybadger (79) Rails (54) JavaScript (47) PHP (36) Python (26) Laravel (23) Briefing (13) DevOps (10) Go (10) Django (9) Elixir (8) Aws (8) Briefing 2021 Q3 (7) FounderQuest (6) Briefing 2021 Q2 (6) Node (6) Conferences (5) Testing (5) Security (4) Developer Tools (4) Elastic Beanstalk (4) Heroku (3) Debugging (3) Docker (3) React (3) Markdown (3) Events (2) Jekyll (2) Startup Advice (2) Guest Post (2) Sidekiq (2) Serverless (2) Git (2) Front End (2) Rspec (2) Oauth (2) Logging (2) GraphQL (2) Error Handling (2) Flask (2) Case Studies (1) Performance (1) Allocation Stats (1) Integrations (1) Bitbucket (1) Mobile (1) Gophercon (1) Clients (1) Vue (1) Lambda (1) Turbolinks (1) Redis (1) CircleCI (1) GitHub (1) Crystal (1) Stripe (1) Saas (1) Elasticsearch (1) Import Maps (1) Build Systems (1) Minitest (1) Guzzle (1) Tdd (1) I18n (1) Github Actions (1) Sql (1) Postgresql (1) Xdebug (1) Zend Debugger (1) Phpdbg (1) Pdf (1) Multithreading (1) Concurrency (1) Web Workers (1) Fargate (1) Websockets (1) Active Record (1) Django Q (1) Celery (1) Amazon S3 (1) Aws Lambda (1) Amazon Textract (1) Sucrase (1) Babel (1) Pdfs (1) Hanami (1) Discord (1) Active Support (1) Blazer (1) Ubuntu (1) Nextjs (1) DynamoDB (1)ĭiscord is a platform that enables people to talk over voice, video, and text, as well as hang out with their friends and communities.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |