Cell Discord SDK
Cell bindings for the Discord Social SDK.
Setup
- Download the Discord Social SDK from the Discord Developer Portal
- Extract to
discord_social_sdk/in this directory - Configure your application in
config.cm
Configuration
Edit config.cm with your Discord application details:
return {
APPLICATION_ID: 1234567890123456789n, // Your app ID (as BigInt)
PUBLIC_KEY: "your_public_key_here",
REDIRECT_URI: "http://127.0.0.1/callback",
CALLBACK_INTERVAL: 16
}
API Reference
Core Functions
discord.init(application_id)- Initialize the Discord clientdiscord.run_callbacks()- Process Discord callbacks (call regularly)discord.shutdown()- Disconnect and clean updiscord.get_status()- Get connection status: "not_initialized", "disconnected", "connecting", "connected", "ready", "reconnecting"discord.is_authenticated()- Check if authenticateddiscord.connect()- Connect to Discorddiscord.disconnect()- Disconnect from Discord
Callback Registration
discord.on_status_changed(callback)- Status change callback:function(status, error, detail)discord.on_log(callback, min_severity)- Log callback:function(message, severity)
Authentication
discord.get_default_scopes()- Get default OAuth2 scopesdiscord.authorize(callback)- Start OAuth2 flow:function(success, code, redirect_uri, error)discord.get_token(code, redirect_uri, callback)- Exchange code for token:function(result)discord.update_token(type, token, callback)- Update access token:function(success, error)discord.refresh_token(refresh_token, callback)- Refresh access token:function(result)
User API
discord.get_current_user()- Get current user objectdiscord.get_user(user_id)- Get user by ID
User object properties:
id- BigInt user IDusername- Usernamedisplay_name- Display nameglobal_name- Global name (optional)avatar_url- Avatar URLstatus- "online", "offline", "idle", "dnd"is_provisional- Is provisional account
Relationships API
discord.get_relationships()- Get all relationships (friends list)discord.get_friends_count()- Get number of friends
Relationship object properties:
id- BigInt user IDtype- "none", "friend", "blocked", "pending_incoming", "pending_outgoing"user- User object
Rich Presence API
discord.update_rich_presence(activity, callback)- Update rich presencediscord.clear_rich_presence()- Clear rich presence
Activity object properties:
type- "playing", "streaming", "listening", "watching", "competing"state- Current state textdetails- Details textlarge_image- Large image keylarge_text- Large image tooltipsmall_image- Small image keysmall_text- Small image tooltipstart_timestamp- Start time (Unix ms)end_timestamp- End time (Unix ms)party_id- Party IDparty_size- Current party sizeparty_max- Max party sizejoin_secret- Join secret for invites
Example Usage
var discord = use("discord")
var config = use("config")
// Initialize
discord.init(config.APPLICATION_ID)
// Set up callbacks
discord.on_status_changed(function(status, error, detail) {
log.console(`Status: ${status}`)
if (status == "ready") {
var user = discord.get_current_user()
log.console(`Logged in as: ${user.display_name}`)
// Set rich presence
discord.update_rich_presence({
type: "playing",
state: "In Game",
details: "Level 5"
})
}
})
// Start auth flow
discord.authorize(function(success, code, redirect_uri, error) {
if (success) {
discord.get_token(code, redirect_uri, function(result) {
if (result.success) {
discord.update_token("bearer", result.access_token, function(ok) {
if (ok) discord.connect()
})
}
})
}
})
// Main loop - call regularly
function tick() {
discord.run_callbacks()
$_.delay(tick, 16)
}
tick()
Running Tests
cd cell-discord
cell test
Running Example
cd cell-discord
cell examples/discord_example
Description
Languages
C++
100%