Discord API
Overview
The discordApi bridge provides a simple interface for interacting with the Discord REST API through an internal bot integration.
It allows Ocean resources to manage:
- Guild information
- Discord members
- Roles
- Messages
- Bans
- Nicknames
The API automatically connects to the configured Discord guild when initialized and caches user data to reduce API calls.
Requirements
A Discord bot must be configured inside:
The bot must have permissions for:
- Manage Roles
- Manage Messages
- Ban Members
- View Members
- Manage Nicknames
Export
discordApi
Returns the initialized Discord API instance.
- Returns:
discordApi
Discord API Class
Functions
getGuild
Returns information about the configured Discord guild.
callback:function(guild)- Returns:
nil
Example:
getDiscordUser
Returns a guild member. Results are cached automatically.
discordId:stringcallback:function(member)- Returns:
nil
Example:
getRoles
Returns all guild roles.
callback:function(roles)- Returns:
nil
userHasRole
Checks if a Discord user has a specific role.
discordId:stringroleId:stringcallback:function(hasRole)- Returns:
nil
Example:
addRole
Adds a role to a Discord user.
discordId:stringroleId:stringcallback:function(success)- Returns:
nil
removeRole
Removes a role from a Discord user.
discordId:stringroleId:stringcallback:function(success)- Returns:
nil
sendMessage
Sends a message to a Discord channel.
channelId:string(optional)content:stringcallback:function(message)- Returns:
nil
If no channel is provided, the default configured channel is used.
Example:
getMessages
Returns recent messages from a channel.
channelId:string(optional)limit:number(1–100)callback:function(messages)- Returns:
nil
Example:
isUserBanned
Checks if a user is banned.
discordId:stringcallback:function(banned, reason)- Returns:
nil
banUser
Bans a Discord user.
discordId:stringdeleteMessageDays:number(0–7)callback:function(success)- Returns:
nil
Example:
unbanUser
Removes a Discord ban.
discordId:stringcallback:function(success)- Returns:
nil
setNickname
Changes a user's nickname.
discordId:stringnickname:string | nilcallback:function(success)- Returns:
nil
Setting nickname to nil resets it.
Example:
invalidateCache
Clears a cached Discord user so fresh data will be fetched on next request.
discordId:string- Returns:
nil
Internal Behavior
The API automatically:
- Connects to the Discord guild on startup
- Caches member data
- Validates HTTP responses
- Logs connection status
- Handles API errors safely
Example
Summary
Discord API provides:
- Discord guild integration
- Role management
- Messaging support
- Moderation tools
- User caching
- Bot based automation
Designed to be a lightweight internal bridge between Ocean resources and Discord.