Discord is a popular chat app, much like Slack. In this tutorial, we’ll show you how to connect the Discord API to Google Sheets in 7 steps:
Apipheny is an API connector for Google Sheets. You can use Apipheny to connect your Google Sheets to unlimited API data sources, make unlimited API requests, and more. There is a 30 day free trial included.
1.) Install Apipheny by opening the following link on desktop and then clicking the Install button in the Google Marketplace: https://apipheny.io/install
2.) After you’ve installed Apipheny, open a Google Sheet and then click on the Extensions dropdown in the menu at the top.
In the dropdown list you should see Apipheny. Click Apipheny then click Import API to open the Apipheny sidebar in your Google Sheet.
Tip: you can open a new Google Sheet by entering this URL in your browser: sheet.new
Go to https://discord.com/developers/applications and click the New Application button:
In the Create an application popup, complete the Name field and then click the Create button:
Your app will then be created and the client id and secret will be displayed on the screen:
Click the Copy button and then paste these values to a safe location, because you will need the ID and client secret in the following steps.
In the OAuth2 section, add a redirect URI by clicking the Add Redirect button:
Complete the Redirects field with any valid URL and then save the changes by clicking the Save Changes button:
Go to the following link into your browser:
https://discordapp.com/api/oauth2/authorize?response_type=code&client_id=your_client_id&scope=identify%20guilds.join&state=15773059ghq9183habn&redirect_uri=your_redirect_uri&prompt=consent
Don’t forget to replace your_client_id and your_redirect_uri values with the ones you obtained in Step 2 above.
Then you’ll be asked to authorize the action. Click the Authorize button:
You’ll then be redirected to your redirect URL. At the end of the URL, you’ll find the required code:
Copy the value after the “code“ parameter to a safe location, because you’ll need it later.
Open up a command prompt window (for Windows OS) or a terminal (for Mac OS) and enter the following command:
curl -X POST "https://discordapp.com/api/oauth2/token" --data "client_id=your_client_id" --data "client_secret=your_client_secret" --data "grant_type=authorization_code" --data "code=your_code" --data "redirect_uri=your_redirect_URI" --data "scope=identify"
Note: For Mac OS you may need to use single quotes ( ' ) instead of double quotes ( " ).
Don’t forget to replace these values:
Your Bearer access token will then be displayed in the response:
Copy and paste your Bearer access token to a safe location because you’ll need it later.
Note: If the token/key that you generate has an expiration time, you will need to complete this same process again to get a new token when the old one expires.
In this section, we’ll show you how to browse the Discord API documentation to find an API endpoint URL that retrieves the information you need. If you already know your endpoint URL, or you want to use the same example URL as us, just skip to Step 6.
First, open the Discord API documentation page: https://discord.com/developers/docs/reference
The menu on the left contains a list of categorized endpoints for the Discord API:
In this case, we’ll use the Invite category, which contains two endpoints: Get invite and Delete invite.
An example endpoint is the Get invite endpoint, which returns an invite object for the given code:
https://discordapp.com/api/v9/invites/{invite.code}
The documentation for this endpoint contains the HTTP method used (GET) and the request path, a short description of the endpoint’s purpose and a table describing the accepted parameters:
All API calls to Discord should be made to the https://discordapp.com/api/v9/ base domain.
Discord API base/root URL:
https://discord.com/api/v10/
Note: Discord changes the version of their API often. Check their documentation to confirm the latest version and update the version number in the URL if necessary.
The Get Channel Message endpoint, which returns a specific message in the channel:
Method: GET API URL Path: https://discord.com/api/v10/channels/{channel.id}/messages/{message.id} Headers: Header 1 Key: Authorization Header 1 Value: Bearer your_token
Make sure to replace your_token with the token you previously obtained, {channel.id} and {message.id} with real values.
The Get Pinned Messages endpoint, which returns all pinned messages in the channel as an array of message objects.
Method: GET API URL Path: https://discord.com/api/v10/channels/{channel.id}/pins Headers: Header 1 Key: Authorization Header 1 Value: Bearer your_token
Make sure to replace your_token with the token you previously obtained and {channel.id} with a real value.
The List Guild Stickers endpoint, which returns an array of sticker objects for the given guild.
Method: GET API URL Path: https://discord.com/api/v10/guilds/{guild.id}/stickers Headers: Header 1 Key: Authorization Header 1 Value: Bearer your_token
Make sure to replace your_token with the token you previously obtained and {guild.id} with a real value.
The Join Thread endpoint, which adds the current user to a thread. Also requires the thread is not archived.
Method: PUT API URL Path: https://discord.com/api/v10/channels/{channel.id}/thread-members/@me Headers: Header 1 Key: Authorization Header 1 Value: Bearer your_token
Make sure to replace your_token with the token you previously obtained and {channel.id} with a real value.
The Leave Thread endpoint, which removes the current user from a thread. Also requires the thread is not archived.
Method: DELETE API URL Path: https://discord.com/api/v10/channels/{channel.id}/thread-members/@me Headers: Header 1 Key: Authorization Header 1 Value: Bearer your_token
Make sure to replace your_token with the token you previously obtained and {channel.id} with a real value.
The Get Reactions endpoint, which gets a list of users that reacted with this emoji. Returns an array of user objects on success.
Method: GET API URL Path: https://discord.com/api/v10/channels/{channel.id}/messages/{message.id}/reactions/{emoji} Headers: Header 1 Key: Authorization Header 1 Value: Bearer your_token
Make sure to replace your_token with the token you previously obtained, {channel.id}, {message.id} and {emoji} with real values. The {emoji} must be URL Encoded or the request will fail.
Now go back to your Google Sheet and make sure that the Apipheny add-on is open on the “Import” tab. With the Import Tab open, enter these details into the add-on:
Method: At the top of the Apipheny sidebar, select the HTTP method (GET or POST) required by your API endpoint. For this example, we are using the GET method.
API URL: In Step 5, we explained how you can find the Discord API endpoint that you need. Now copy the complete URL into the Apipheny add-on, where it says API URL Path (JSON / CSV), followed by any GET parameters required for your query.
For this example, we are using the Get current user endpoint that returns the current user. The corresponding URL is:
https://discord.com/api/v10/users/@me
Headers: In the Headers section, add one row with the following key and value:
Key: Authorization Value: Bearer your_token
Replace your_token with the value of the token you generated previously, in Step 4. There should be a space between Bearer and your_token.
Lastly, click the Run button at the bottom of the Apipheny add-on and then wait for the Discord API data to be pulled in to your Google Sheet:
After making a successful request to the Discord API, try querying a different endpoint, or try using one of the more advanced features in the Apipheny add-on.
Pagination is a process that is used to divide a large dataset into smaller chunks (pages). Usually the endpoints that return a list of resources support pagination.
The GET /guilds/{guild.id}/bans endpoint has been migrated to require pagination to improve reliability and stability.
This means you need to add pagination some of these parameters at the end of the URL:
before
– consider only users before given user id;after
– consider only users after given user id;limit
– number of users to return (up to maximum 1000). Default value is 1000.Each endpoint that needs pagination will have in its documentation relevant information on which of these parameters you can use and how to do it.
Crypto API Tutorials: