Giter Site home page Giter Site logo

badger_discord_api's Introduction

Badger_Discord_API

Visitor Count

Documentation

Installation Guide

API Development/ Implementation Docs

Jared's Developer Community [Discord]

Developer Discord

Sponsors

Sponsor Sponsor Message
Sponsored by North American Roleplaying Community - NARC

Visit us @ https://discord.gg/NARC

Enemy of the State Roleplay

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 :) 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 :P

Scripts that utilize the API

https://forum.cfx.re/t/release-badgertools-major-revamp/665756/ https://forum.cfx.re/t/discordaceperms-release/573044 https://forum.cfx.re/t/release-bad-discordqueue-a-discord-role-based-queue-system-by-badger/1394685 https://forum.cfx.re/t/discordtagids-i-know-i-know-i-only-make-discord-based-scripts/582513 https://forum.cfx.re/t/discordchatroles-release/566338

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 

-- function SetNickname(user, nickname)
-- Returns error code 403 if the user is higher than the bot
-- Usage:
	SetNickname(user, "🦡Badger", "Set nickname")
	SetNickname(user, "", "Reset nickname")
	
-- function AddRole(user, roleId, reason)
-- Returns error code 403 if the user is higher than the bot
-- Usage:
	AddRole(user, "1038448129709723670", "Add role")

-- function SetRoles(user, roleList, reason)
-- Returns error code 403 if the user is higher than the bot
-- Usage:
	SetRoles(user, { "1038448129709723670" }, "Set roles")

-- function RemoveRole(user, roleId, reason)
-- Returns error code 403 if the user is higher than the bot
-- Usage:
	RemoveRole(user, "1038448129709723670", "Remove role")

-- function ChangeDiscordVoice(user, voiceID)
-- Returns error code 400 if voice channel ID is incorrect
-- Usage:
	ChangeDiscordVoice(user, 123456789123456789)
	ChangeDiscordVoice(user, 123456789123456789, "Moved "..GetPlayerName(user).." to the admin channel")
end)

Download

https://github.com/JaredScar/Badger_Discord_API

badger_discord_api's People

Contributors

ach-git avatar coleminer0112 avatar creativewild avatar fsocietystudios avatar gegelendvay avatar grandparex avatar jaredscar avatar jordan2139 avatar nickreagan avatar realcallmej avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

badger_discord_api's Issues

Add functunality

Hey, that would be great if you can add a fonction to check if a player has a specific role. This could return a boolean value.

suggestion - birthday/date of birth

it is possible to obtain the birthday date or date of birth or age to create a wl system via age, for example prohibiting the server at least 18 years old

Support

Config = {
Guild_ID = '1067585176969957396', -- Set to the ID of your guild (or your Primary guild if using Multiguild)
Multiguild = false, -- Set to true if you want to use multiple guilds
Guilds = {
["main"] = "1067585176969957396", -- Replace this with a name, like "main"
},
Bot_Token = '[REDACTED],
RoleList = {
['Owner'] = 1067912263501086740,
['Co-Owner'] = 1067912264805531819,
['Flux-keys'] = 1068287416164679700,
['HighStaff'] = 1067912316106047488,
['SeniorStaff'] = 1067912317813149756,
['Staff'] = 1067912319029493860,
['TACOPS'] = 1067912388784959559,
['Server_Booster'] = 1067957120194068550,
['hidden'] = 1077980374703022160,
['Member'] = 1068680726649782423
['2018Charger'] = 1067912377246421085,
},
CacheDiscordRoles = true, -- true to cache player roles, false to make a new Discord Request every time
CacheDiscordRolesTime = 60, -- if CacheDiscordRoles is true, how long to cache roles before clearing (in seconds)
}

Config.Splash = {
Header_IMG = 'https://cdn.discordapp.com/attachments/1057657624272830595/1059553028602069113/IMG_4603.png',
Enabled = true,
Wait = 10, -- How many seconds should splash page be shown for? (Max is 12)
Heading1 = "Welcome to Florida State Roleplay",
Heading2 = "Make sure to join our Discord and check out our website!",
Discord_Link = 'https://discord.gg/DwfA2y6CQr',
Website_Link = '',
}

Can someone help why I'm getting errors.

image

Problem with the api and discord ace perms

Hi. i followed the tutorial for api and ace perms. but people can still join my server without a discord role. any ideas of what i am missing?

say what you need of info :)

API Call for SetNickname not functioning

So I am attempting to use the SetNickname export, I've followed the included example in the example.lua

My code;

exports.Badger_Discord_API:SetNickname(source, "Test Name", "New Name")

I'm using this in a server script, I'm calling source from the source arg passed by the RegisterCommand native.

I keep getting the message

[Badger_Perms] ERROR: Code 200 was not reached. Error Code: Error - The request was improperly formatted, or the server couldn't understand it..!

DiscordAcePerms Multiguild Issue

DiscordAcePerms only reads roles from the Guild placed in Guild_ID in Badger API. I have set the Multiguild = true, and placed both guild's in the Guilds = { and it still only reads the guild in the Guild_ID. I've tested with vehicle-restrict and a few others and none of them identify the multiguild with DiscordAcePerms.

Asked for Support in Badgers discord and he informed me to make a Issue on the GitHub. Was told to mention @coleminer0112

Discord rate limit

Badger sends to many requests to the Discord API resulting in a rate limit.

script:Badger_Discor] [Badger_Perms] ERROR: Code 200 was not reached... Returning false. [Member Data NOT FOUND] DETAILS: Error - Too many requests, you hit the Discord rate limit. https://discord.com/developers/docs/topics/rate-limits

Using POST or PATCH requests

When I use the DiscordRequest function with POST or PATCH methods, and try to pass jsondata with it, I get error code 400 (bad request). Example for changing user nickname:

function SetNickname(user, nickname)
	local discordId = nil
	for _, id in ipairs(GetPlayerIdentifiers(user)) do
		if string.match(id, "discord:") then
			discordId = string.gsub(id, "discord:", "")
			break
		end
	end

	if discordId then
		local name = nickname or ""
		local endpoint = ("guilds/%s/members/%s"):format(Config.GuildId, discordId)
		local member = DiscordRequest("PATCH", endpoint, {nick = name})
		print(member.code) --Returns 400
	end
end

By printing out jsondata in the DiscordRequest function, I get a table. My guess is that the Discord API can't read that, hence why it returns error code 400. After trying to solve this issue for a while now with no success, could anyone tell me a way to fix it without doing the HTTP request in my SetNickname function itself?
image

API only returns 401 Status

Any time we try and start the script, we get a 401 status code from Discord. I played around with the URIs in Postman, and can only get 401 or 504 errors. Is there any specific changes to the authentication header that needs to happen so we can get a 200 OK status code, or is this issue with the Discord API?

Everyone got crashed

[ script:hardcap] Connecting: James smith
[script:Badger_Discor] [Badger_Perms] ERROR: Code 200 was not reached... Returning false. [Member Data NOT FOUND]
[ script:Guardian] [Guardian] (playerConnecting) Player James smith Could not connect because role id's were not present
[ script:Guardian] [Guardian] (playerConnecting) Player James smith Attempted to connect with Guardian, however they failed

REOPEN: Rate limit issue

Badger sends to many requests to the Discord API resulting in a rate limit.

script:Badger_Discor] [Badger_Perms] ERROR: Code 200 was not reached... Returning false. [Member Data NOT FOUND] DETAILS: Error - Too many requests, you hit the Discord rate limit. https://discord.com/developers/docs/topics/rate-limits

Rate limit does not work. Atleas not with 200 players.
Continously erroring in the console, players not getting their roles etc (Only using Badger Discord perms and API)

Stop being ignorant, the script does not work correctly with high player counts

[BUG] No such export GetDiscordRoles in resource Badger_Discord_API

[script:DiscordAcePer] SCRIPT ERROR: citizen:/scripting/lua/scheduler.lua:881: No such export GetDiscordRoles in resource Badger_Discord_API

What is this? I can't get into the server :( stuck at Deferring Roles

Update... issue resolved. Someone made a syntax error in the config.lua.

Non discord members are able to join

Hello,

I've been testing out this script and I do like it, but yesterday someone who is not member of the Discord server was able to join my server anyway.
Today I tried it out with a test Discord account and I was also able to join the server without being member of the Discord.

When trying to join the screen that you must join Discord first is being shown, which is perfectly fine.

image

But when you click the Play button on above mentioned screen without joining the Discord server, you are allowed in the game anyway and below error is being shown in the server console:

[script:Badger_Discor] [Badger_Perms] ERROR: Code 200 was not reached... Returning false. [Member Data NOT FOUND] DETAILS: Error - The resource at the location specified doesn't exist.
[ script:connectqueue] QUEUE: username[license:***] was placed 1/1 in queue
[ script:connectqueue] QUEUE: username[license:***] is loading into the server

Versioning

I really believe versioning is an absolutely necessary thing to do for any library.
You should create releases or tags at least containing version numbers so that scripts depending on this library can reference a specific version. Libraries without versions like this are one of the major causes of "dependency hell" and scripts that don't work.

isRolePresent Error

Getting the SCRIPT ERROR: citizen:/scripting/lua/scheduler.lua:903: No such export isRolePresent in resource discordroles
error in my server console, no I did not rename it to anything else.

image
image
image
image

Header Image Idea

Would it be possible to have a selection of HEADER IMG?
Where it randomly selects one of a few to show someone when they join?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.