Developer Reference Discord - DaemonForge/DayZ-UniveralApi GitHub Wiki
Discord Developer Reference
You can access the Discord API function using UApi().ds().
Example Usage
UApi().ds().AddRole("GUID", "ROLEID");
UApi().ds().UserSend("GUID", "Message to dm to user");
UApi().ds().ChannelMessages("CHANNELID", CallbackInstance, "CBCallBackFunction");
protected void CBCallBackFunction(int cid, int status, string oid/*Channel ID*/, UApiDiscordMessagesResponse data) {
if ( status == UAPI_SUCCESS ){
//Do something with data
autoptr array<UApiDiscordMessage> Messages = data.Messages;
}
}
- Setting
ReturnStringtotruewill return JSON Strings instead of objects
User Functions
Get User
This will return a UApiDiscordUser Object that contains the roles and discord info
- Client side you can only get the player's Discord Object for the player the auth token is issued to
int GetUser(string GUID, Class cbInstance, string cbFunction, bool ReturnString = false) {}
GetUser Callback function
protected void CBCallBackFunction(int cid, int status, string oid/*GUID/PlainID*/, UApiDiscordUser data) {
if ( status == UAPI_SUCCESS ){
//Do something with data
} else if ( status == UAPI_NOTSETUP ){
//User's Discord isn't setup
} else if ( status == UAPI_NOTFOUND){
//User's Discord is set up but they are no longer part of the discord.
}
}
Add and Remove Discord Roles
- Can Only be used server side
Add Role
int AddRole(string GUID, string RoleId, Class cbInstance = NULL, string cbFunction = "", bool ReturnString = false) {}
Remove Role
int RemoveRole(string GUID, string RoleId, Class cbInstance = NULL, string cbFunction = "", bool ReturnString = false) {}
Add & Remove Roles Callback Function
Returns' the Updated User Object with a status
protected void CBCallBackFunction(int cid, int status, string oid/*GUID/PlainID*/, UApiDiscordUser data) {
if ( status == UAPI_SUCCESS ){
//Do something with data
} else if ( status == UAPI_NOTSETUP ){
//User's Discord isn't setup
} else if ( status == UAPI_NOTFOUND){
//User's Discord is set up but they are no longer part of the discord.
} else {
Print("Error Adding Role: " + data.Error);
}
}
Send Message
Sends a DM to a user's discord returns UApiDiscordStatusObject
- Can Only be used server side
int UserSend(string GUID, string message, Class cbInstance = NULL, string cbFunction = "", bool ReturnString = false){}
Send Message Callback
protected void CBCallBackFunction(int cid, int status, string oid/*GUID/PlainID*/, UApiDiscordStatusObject data) {
if ( status == UAPI_SUCCESS ){
//Do something with data
Print("Message sent to user Message ID is" + data.oid);
} else if ( status == UAPI_NOTSETUP ){
//User's Discord isn't setup
} else {
Print("Error sending DM: " + data.Error);
}
}
Get Users current Voice Channel
int GetUsersChannel(string GUID, Class cbInstance, string cbFunction, bool ReturnString = false) {}
Get Users Channel Callback Function
protected void CBCallBackFunction(int cid, int status, string oid/*GUID*/, UApiDiscordStatusObject data) {
if ( status == UAPI_SUCCESS ){
//Returned user's current voice channel data.oid
} else if ( status == UAPI_NOTFOUND ){
//User isn't in a discord voice channel
} else if ( status == UAPI_NOTSETUP ){
//User's Discord isn't setup
}
}
Move User to Channel
int MoveTo(string GUID, string ChannelId, Class cbInstance = NULL , string cbFunction = "", bool ReturnString = false) {}
Move User To Channel Callback Function
protected void CBCallBackFunction(int cid, int status, string oid/*GUID*/, StatusObject data) {
if ( status == UAPI_SUCCESS ){
//User successfully was moved to channel
} else if ( status == UAPI_NOTFOUND ){
//User isn't in a discord voice channel
} else if ( status == UAPI_NOTSETUP ){
//User's Discord isn't setup
}
}
Kick User from Voice Channels
int KickUser(string GUID, string Reason = "", Class cbInstance = NULL , string cbFunction = "", bool ReturnString = false) {}
Kick User Callback Function
protected void CBCallBackFunction(int cid, int status, string oid/*GUID*/, StatusObject data) {
if ( status == UAPI_SUCCESS ){
//User successfully was kicked from channel
} else if ( status == UAPI_NOTFOUND ){
//User isn't in a discord voice channel
} else if ( status == UAPI_NOTSETUP ){
//User's Discord isn't setup
}
}
Mute User
/*true to mute/false to unmute*/,
int MuteUser(string GUID, bool ToMute, Class cbInstance, string cbFunction, bool ReturnString = false) {}
Mute User Callback Function
protected void CBCallBackFunction(int cid, int status, string oid/*GUID*/, StatusObject data) {
if ( status == UAPI_SUCCESS ){
//User successfully muted user
} else if ( status == UAPI_NOTFOUND ){
//User isn't in a discord voice channel
} else if ( status == UAPI_NOTSETUP ){
//User's Discord isn't setup
}
}
Set Users Discord Nickname
This will not work on the discord server administrators
int SetNickname(string GUID, string Nickname= "", Class cbInstance = NULL , string cbFunction = "", bool ReturnString = false) {}
Set Nickname Callback Function
protected void CBCallBackFunction(int cid, int status, string oid/*GUID*/, StatusObject data) {
if ( status == UAPI_SUCCESS ){
//User successfully was kicked from channel
} else if ( status == UAPI_NOTSETUP ){
//User's Discord isn't setup
}
}
Channel Functions
Create a Channel
- Can Only be used server side
int ChannelCreate(string Name, UApiChannelOptions Options = NULL, Class cbInstance = NULL, string cbFunction = "", bool ReturnString = false) {}
Create Channel Callback
protected void CBCallBackFunction(int cid, int status, string oid/*Channel Name*/, UApiDiscordStatusObject data) {
if ( status == UAPI_SUCCESS ){
Print("Channel was created with the ID of" + data.oid);
}
}
Deletes the Channel in the discord
- Can Only be used server side
int ChannelDelete(string id, string reason, Class cbInstance = NULL, string cbFunction = "", bool ReturnString = false){}
Deletes Channel Callback
protected void CBCallBackFunction(int cid, int status, string oid/*Channel Id*/, UApiDiscordStatusObject data) {
if ( status == UAPI_SUCCESS ){
//Channel was successfully deleted
}
}
Edits a channel in the discord
- Can Only be used server side
int ChannelEdit(string id, string reason, autoptr UApiChannelUpdateOptions options, Class cbInstance = NULL, string cbFunction = "", bool ReturnString = false){}
Edit Channel Callback
protected void CBCallBackFunction(int cid, int status, string oid/*Channel Id*/, UApiDiscordStatusObject data) {
if ( status == UAPI_SUCCESS ){
//Channel was successfully edited
}
}
Sends messages to a channel in the discord
- Server side full permissions that the bot has
- Client side Bot and connected discord user must have Perms as well
int ChannelSend(string id, string message, Class cbInstance = NULL, string cbFunction = "", bool ReturnString = false){}
int ChannelSendEmbed(string id, UApiDiscordEmbed message, Class cbInstance = NULL, string cbFunction = "", bool ReturnString = false){}
Send Messages to Channel Callback
protected void CBCallBackFunction(int cid, int status, string oid/*Channel Id*/, UApiDiscordStatusObject data) {
if ( status == UAPI_SUCCESS ){
Print("Message was sent and has an id of" + data.oid);
} else if (status == UAPI_UNAUTHORIZED){
//Client doesn't have permissions to access the channel
} else if (status == UAPI_NOTFOUND){
//Channel couldn't be found
}
}
Retrieves the messages in a discord channel
Get an array of all the messages in the specified Channel
- Server side full permissions that the bot has
- Client side Bot and connected discord user must have Perms as well
int ChannelMessages(string id, Class cbInstance, string cbFunction, autoptr UApiDiscordChannelFilter filter = NULL, bool ReturnString = false){}
Channel Messages Callback Function
protected void CBCallBackFunction(int cid, int status, string oid/*Channel ID*/, UApiDiscordMessagesResponse data) {
if ( status == UAPI_SUCCESS ){
//Do something with data
autoptr array<UApiDiscordMessage> Messages = data.Messages;
} else if (status == UAPI_UNAUTHORIZED){
//Client doesn't have permissions to access the channel
} else if (status == UAPI_NOTFOUND){
//Channel couldn't be found
}
}
Utility Functions
Link
Returns a link for the player based on the players steam id so they can connect there discord to there steam account, you can also manually pass the SteamID if you want do something server side but leave it blank client side and it will make for the user, the link is just https://[IP]/Discord/[SteamID] if you want to program it and you can use GetDayZGame().GetSteamId() client side to get the steam id.
string Link(string PlainId = ""){}
Check Discord
int CheckDiscord(string PlainId, Class cbInstance, string cbFunction, string baseUrl = "", bool ReturnString = false){}
Check Callback
protected void CBCallBackFunction(int cid, int status, string oid/*GUID/PlainID*/, StatusObject data) {
if ( status == UAPI_SUCCESS ){
//User has a discord account connected
} else if ( status == UAPI_NOTFOUND ){
//User does not have a discord account connected or they have left the discord
}
}
Discord User Object
class UApiDiscordUser extends StatusObject {
/*
id
Discord ID this is the discord id of the player
*/
string id;
/*
Username
Discord Username of the user
*/
string Username;
/*
Discriminator
The four Digit Discriminator for the player
*/
string Discriminator;
/*
Avatar
A link to the player Avatar
*/
string Avatar;
/*
Roles
An Array of all the roles the player has roles are ID#
*/
TStringArray Roles;
/*
VoiceChannel
The ID of the current voice channel the player is in
*/
string VoiceChannel;
/*
HasRole
A quick check if the player has the role specified
*/
bool HasRole(string roleid)
}