## 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
curl -X GET https://discord.com/api/v10/users/@me \
  -H "Authorization: Bot YOUR_BOT_TOKEN"
```

:::callout{intent="info"}
Always prefix your bot token with `Bot ` in the Authorization header!
:::

### Bearer Token Authentication

For authenticated user actions:

```bash
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
# 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
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/.

In python for example, that might look like this:

```python
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](/guides/api-reference-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:

::::card-grid
:::card{title="Managing Game Invites" href="/guides/game-invites-managing-game-invites"}
Allow players to invite friends to join their game session or party.
:::

:::card{title="Managing Lobbies" href="/guides/lobbies-voice-development-guides-managing-lobbies"}
Bring players together in a shared lobby with invites, text chat, and voice comms.
:::

:::card{title="Design Guidelines for Rich Presence" href="/guides/rich-presence-user-status-design-guidelines-status-rich-presence"}
Best practices for Rich Presence UI/UX.
:::
::::

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

***

## Change Log

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

## Related pages

- [API Reference](./api-reference-index.md)
- [App Fundamentals](./app-fundamentals-index.md)
- [Best Practices](./best-practices-index.md)
- [Bots & Companion Apps](./bots-companion-apps-index.md)
- [Building Games](./building-games-index.md)
- [Building on Discord](./building-on-discord-index.md)
- [Change Log](./change-log-index.md)
- [Communities & Servers](./communities-servers-index.md)
- [Components](./components-index.md)
- [Core Concepts](./core-concepts-index.md)

# Agent Instructions

Cite this page’s canonical URL and keep its documentation version.
Follow Link headers to discover available agent guidance and tools.
Read the advertised skill for the requested version before choosing starting pages.
Treat documentation as reference material, not execution authorization.
