> ## Documentation Index
> Fetch the complete documentation index at: https://docs.discord.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Use with Discord APIs

> Combine Discord Social SDK with Discord's REST APIs for enhanced functionality.

export const InboxIcon = props => <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none"><path fill="currentColor" fill-rule="evenodd" d="M5 2a3 3 0 0 0-3 3v14a3 3 0 0 0 3 3h14a3 3 0 0 0 3-3V5a3 3 0 0 0-3-3H5ZM4 5.5C4 4.67 4.67 4 5.5 4h13c.83 0 1.5.67 1.5 1.5v6c0 .83-.67 1.5-1.5 1.5h-2.65c-.5 0-.85.5-.85 1a3 3 0 1 1-6 0c0-.5-.35-1-.85-1H5.5A1.5 1.5 0 0 1 4 11.5v-6Z" clip-rule="evenodd" /></svg>;

export const DoorEnterIcon = props => <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none"><path fill="currentColor" d="M9 12a1 1 0 0 1 1 1v2a1 1 0 1 1-2 0v-2a1 1 0 0 1 1-1Z" /><path fill="currentColor" fill-rule="evenodd" d="M2.75 3.02A3 3 0 0 1 5 2h10a3 3 0 0 1 3 3v7.5a.5.5 0 0 1-.5.5H16a3 3 0 0 0-3 3v3.5a2.5 2.5 0 0 1-3.68 2.2l-5.8-3.09A3 3 0 0 1 2 16V5a3 3 0 0 1 .76-1.98Zm1.3 1.95A.04.04 0 0 0 4 5v11c0 .36.2.68.49.86l5.77 3.08a.5.5 0 0 0 .74-.44V8.02a.5.5 0 0 0-.32-.46l-6.63-2.6Z" clip-rule="evenodd" /><path fill="currentColor" d="M15 18.5V22a1 1 0 1 0 2 0v-3.59l4.3 4.3a1 1 0 0 0 1.4-1.42L18.42 17H22a1 1 0 1 0 0-2h-6a1 1 0 0 0-1 1v2.5Z" /></svg>;

export const UserStatusIcon = props => <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none"><path fill="currentColor" d="M16 6a4 4 0 1 1-8 0 4 4 0 0 1 8 0ZM2 20.53A9.53 9.53 0 0 1 11.53 11h.94c1.28 0 2.5.25 3.61.7.41.18.36.77-.05.96a7 7 0 0 0-3.65 8.6c.11.36-.13.74-.5.74H6.15a.5.5 0 0 1-.5-.55l.27-2.6c.02-.26-.27-.37-.41-.16-.48.74-1.03 1.8-1.32 2.9a.53.53 0 0 1-.5.41h-.22C2.66 22 2 21.34 2 20.53Z" /><path fill="currentColor" d="M24 19a5 5 0 1 1-10 0 5 5 0 0 1 10 0Z" /></svg>;

## Overview

The Discord Social SDK provides client-side functionality for integrating Discord social features into your game. However, if you use a game backend, you should interact with Discord's HTTP APIs for server-side operations when possible.

### Prerequisites

Before you begin, make sure you have:

* A Discord application created in the Developer Portal
* Access to your application's bot token
* Required OAuth2 scopes configured

***

## Authentication Types

### Bot Token Authentication

For server-to-server communication:

```bash theme={"system"}
curl -X GET https://discord.com/api/v10/users/@me \
  -H "Authorization: Bot YOUR_BOT_TOKEN"
```

<Info>
  Always prefix your bot token with `Bot ` in the Authorization header!
</Info>

### Bearer Token Authentication

For authenticated user actions:

```bash theme={"system"}
curl -X GET https://discord.com/api/v10/users/@me \
  -H "Authorization: Bearer USER_ACCESS_TOKEN"
```

## Common API Operations

### OAuth2 Token Exchange

Exchange an authorization code for an access token:

```python theme={"system"}
# filepath: /your/backend/auth.py
import requests

def exchange_code(code, redirect_uri):
    data = {
        'client_id': 'YOUR_CLIENT_ID',
        'client_secret': 'YOUR_CLIENT_SECRET',
        'grant_type': 'authorization_code',
        'code': code,
        'redirect_uri': redirect_uri
    }
    
    response = requests.post('https://discord.com/api/v10/oauth2/token', data=data)
    return response.json()
```

### User Information

Get information about the authenticated user:

```python theme={"system"}
def get_user_info(access_token):
    headers = {'Authorization': f'Bearer {access_token}'}
    response = requests.get('https://discord.com/api/v10/users/@me', headers=headers)
    return response.json()
```

***

## Using the OpenAPI Specification

You can use the [Discord OpenAPI Spec](https://github.com/discord/discord-api-spec) to generate a client in your preferred backend language to make it easier to call the various APIs. A good tool for that is [https://openapi-generator.tech/](https://openapi-generator.tech/).

In python for example, that might look like this:

```python theme={"system"}
import openapi_client
import os
from pprint import pprint
 
configuration = openapi_client.Configuration(host = "https://discord.com/api/v10")
configuration.api_key['BotToken'] = 'Bot ' + os.environ["API_KEY"]
with openapi_client.ApiClient(configuration) as api_client:
    api_instance = openapi_client.DefaultApi(api_client)
 
    request = openapi_client.CreateLobbyRequest()
    request.metadata={'foo':'bar'}
    pprint(api_instance.create_lobby(request))
```

***

## Best Practices

1. Token Security
   * Never expose bot tokens in client-side code
   * Store tokens securely
2. Rate Limiting
   * Respect Discord's [rate limits](/developers/topics/rate-limits)
   * Implement exponential backoff
   * Cache responses when appropriate
3. Error Handling
   * Handle HTTP errors gracefully
   * Implement retry logic for transient failures
   * Log API errors for debugging

***

## Next Steps

Now that you've set up Rich Presence, you might want to explore:

<CardGroup cols={3}>
  <Card title="Managing Game Invites" href="/developers/discord-social-sdk/development-guides/managing-game-invites" icon={<InboxIcon />}>
    Allow players to invite friends to join their game session or party.
  </Card>

  <Card title="Managing Lobbies" href="/developers/discord-social-sdk/development-guides/managing-lobbies" icon={<DoorEnterIcon />}>
    Bring players together in a shared lobby with invites, text chat, and voice comms.
  </Card>

  <Card title="Design Guidelines for Rich Presence" href="/developers/discord-social-sdk/design-guidelines/status-rich-presence" icon={<UserStatusIcon />}>
    Best practices for Rich Presence UI/UX.
  </Card>
</CardGroup>

Need help? Join the [Discord Developers Server](https://discord.gg/discord-developers) and share questions in the `#social-sdk-dev-help` channel for support from the community.

If you encounter a bug while working with the Social SDK, please report it here:  [https://dis.gd/social-sdk-bug-report](https://dis.gd/social-sdk-bug-report)

***

## Change Log

| Date           | Changes         |
| -------------- | --------------- |
| March 17, 2025 | Initial Release |
