[RELEASE] Badger_Discord_API

Badger_Discord_API

Documentation

Notes

Some methods of the API not may fully work or be broken. I was able to test most and 75% of it works. If something does not work, please just submit an issue or pull request for it on the GitHub page. I will be making a more reinforced documentation for this whole API sometime in the future, but for now please just make use of the example.lua file for understanding it all. Thanks!

What is it?

This is essentially a Discord API for FiveM. It utilizes the REST API of Discord for all your essential needs :slight_smile: Things that are heavy in Discord rate limiting (such as retreiving all server roles and player avatars) will be automatically stored to a cache for developers automatically. I will be moving all my scripts over to use this API for better ease of use. Some features include not having to gather role IDs at all, since the script gets the server’s roles automatically, so you can just specify the role’s name instead of role IDs at all (however, be aware that this will break then if someone changes the roles’ names on Discord)… I hope you can all find some use for this, I know I will :stuck_out_tongue:

Scripts that utilize the API

Example Usage:

-- IMPORTANT:
-- For use in other resources, you will need to use: 
--     exports.Badger_Discord_API:<function>
--
-- For example:
--		exports.Badger_Discord_API:GetRoleIdFromRoleName("roleName")

RegisterCommand('testResource', function(source, args, rawCommand)
	local user = source; -- The user 



-- function GetRoleIdFromRoleName(name)
-- Returns nil if not found
-- Returns Discord Role ID if found
-- Usage:
	local roleName = "Founder"; -- Change this to an existing role name on your Discord server 

	local roleID = GetRoleIdFromRoleName(roleName);
	print("[Badger_Perms Example] The roleID for (" .. roleName .. ") is: " .. tostring(roleID));

-- function IsDiscordEmailVerified(user)
-- Returns false if not found
-- Returns true if verified 
-- Usage:
	local isVerified = IsDiscordEmailVerified(user);
	print("[Badger_Perms Example] Player " .. GetPlayerName(user) .. " has Discord email verified?: " .. tostring(isVerified));

-- function GetDiscordEmail(user)
-- Returns nil if not found
-- Returns Email if found 
-- Usage:
	local emailAddr = GetDiscordEmail(user);
	print("[Badger_Perms Example] Player " .. GetPlayerName(user) .. " has Discord email address: " .. tostring(emailAddr));

-- function GetDiscordName(user)
-- Returns nil if not found
-- Returns Discord name if found 
-- Usage:
	local name = GetDiscordName(user);
	print("[Badger_Perms Example] Player " .. GetPlayerName(user) .. " has Discord name: " .. tostring(name));

-- function GetGuildIcon()
-- Returns nil if not found
-- Returns URL if found 
-- Usage:
	local icon_URL = GetGuildIcon();
	print("[Badger_Perms Example] Guild icon URL is: " .. tostring(icon_URL));

-- function GetGuildSplash()
-- Returns nil if not found
-- Returns URL if found 
-- Usage:
	local splash_URL = GetGuildSplash();
	print("[Badger_Perms Example] Guild splash URL is: " .. tostring(splash_URL));

-- function GetGuildName()
-- Returns nil if not found
-- Returns name if found 
-- Usage:
	local guildName = GetGuildName();
	print("[Badger_Perms Example] Guild name is: " .. tostring(guildName));

-- function GetGuildDescription()
-- Returns nil if not found
-- Returns description if found 
-- Usage:
	local guildDesc = GetGuildDescription();
	print("[Badger_Perms Example] Guild description is: " .. tostring(guildDesc));

-- function GetGuildMemberCount()
-- Returns nil if not found
-- Returns member count if found 
-- Usage:
	local guildMemCount = GetGuildMemberCount();
	print("[Badger_Perms Example] Guild member count is: " .. tostring(guildMemCount));

-- function GetGuildOnlineMemberCount()
-- Returns nil if not found
-- Returns description if found 
-- Usage:
	local onlineMemCount = GetGuildOnlineMemberCount();
	print("[Badger_Perms Example] Guild online member count is: " .. tostring(onlineMemCount));

-- function GetDiscordAvatar(user)
-- Returns nil if not found
-- Returns URL if found 
-- Usage:
	local avatar = GetDiscordAvatar(user);
	print("[Badger_Perms Example] Player " .. GetPlayerName(user) .. " has Discord avatar: " .. tostring(avatar));

-- function GetDiscordNickname(user)
-- Returns nil if not found
-- Returns nickname if found 
-- Usage:
	local nickname = GetDiscordNickname(user);
	print("[Badger_Perms Example] Player " .. GetPlayerName(user) .. " has Discord nickname: " .. tostring(nickname));

-- function GetGuildRoleList()
-- Returns nil if not found
-- Returns associative array if found 
-- Usage:
	local roles = GetGuildRoleList();
	for roleName, roleID in pairs(roles) do 
		print(roleName .. " === " .. roleID);
	end

-- function GetDiscordRoles(user)
-- Returns nil if not found
-- Returns array if found 
-- Usage:
	local roles = GetDiscordRoles(user)
	for i = 1, #roles do  
		print(roles[i]);
	end

-- function CheckEqual(role1, role2)
-- Returns false if not equal
-- Returns true if equal 
-- Usage:
	local isRolesEqual = CheckEqual("Founder", 597446100206616596);
	local isRolesEqual2 = CheckEqual("FounderRef", "Founder"); -- Refer to config.lua file, this is basically checking if FounderRef in the config is 
	-- equal to the Founder role's ID 
end)

Download

No Advertisements Version (Paid)

https://store.collectivem.org/category/scripts

92 Likes

Top show badger… keen to try this out

1 Like

That’s the spirit Badger. You’re a cool guy, thanks for the share

1 Like

how to give user a spesfic role?

What do you mean? Did you even read the post? :man_facepalming:

1 Like

Refer to for examples:

Scripts that utilize the API





5 Likes

Official Documentation released

2 Likes

New Installation Tutorial [Badger_Discord_API]

Thank you to @Jordan2139

4 Likes

Always with the discord related projects huh? lmfao. Good stuff tho

Amazing release.
Definitely worth a look at.

2 Likes

This is just awesome, and I hope one day I will make it work, thankyou Badger, anyhow this is great, and ty jordan for being awesome!

I’m using the following resources in my server to link discord roles to ace permissions in my fivem server. I am using “discord_perms”, “Badger_Discord_API” and “DiscordAcePerms”. I have it setup like it should be and have my server.cfg like he says to here:

# Discord Permissions
add_ace resource.DiscordAcePerms command.add_principal allow
add_ace resource.DiscordAcePerms command.remove_principal allow
start Badger_Discord_API
start discord_perms
start DiscordAcePerms

I get no error until a user tries to join the server and when they do I get an error in the console stating: SCRIPT ERROR: citizen/scripting/lua/scheduler.lua:903: No such export GetDiscordRoles in resource Badger_Discord_API Let me know if anyone has any solutions

here are the links to those resources also if you would like to try and recreate the error: Discord API: [RELEASE] Badger_Discord_API DiscordAcePerms: DiscordAcePerms [Release] and discord_perms: Discord roles for permissions (im creative, i know)

1 Like

What does t his mean. Couldn’t find resource DiscordAcePerms.
and how do i fix it

1 Like

You Need to install DiscordAcePerms

1 Like

The script "Badger_Discord_API isn’t set up right

1 Like


How can I fix this?

1 Like

It was a typo. Just updated the fix:

4 Likes

What is your discord server?

1 Like

Check my profile. I am not allowed to post it on the forums

I didn’t know you needed this for DiscordAcePerms and literally all the discord scripts lol

1 Like