Skip to content

GetDiscordMemberRoles

Reads the roles of a member of your Discord server, with your own bot.

Asks Discord, with the bot token you give, for the member’s roles in your Discord server, and calls callback(roles) with a list of role ids (strings) when Discord answered, or callback(nil, problem):

problem What it means
"not a member" Discord does not know them in that Discord server
"bad bot token" the token is wrong or was reset
"the bot is not in that Discord server" invite the bot first
"rate limited" asked too often - keep the answers for a minute (OnPlayerJoinRequest asks twice a join)
"unreachable: ..." Discord did not answer
"not a Discord id" the guild or member id is not one

The bot needs no permission beyond being a member of the Discord server, and the Server Members Intent turned on in Discord’s Developer Portal. Keep its token out of anything players can read. The callback runs on the server’s simulation thread, like a database’s.

GetDiscordMemberRoles(guildId, discordId, botToken, callback)
Parameter Type
guildId string your Discord server’s id (Discord’s developer mode, right-click the server, Copy Server ID)
discordId string the member - GetPlayerDiscordId or join.discord
botToken string your bot’s token
callback function function(roles, problem)
local GUILD, ROLE, TOKEN = "111111111111111111", "222222222222222222", "your bot token"
function OnPlayerJoinRequest(ask, join)
if not join.discord then return false, "Sign in with Discord in the launcher's Options." end
GetDiscordMemberRoles(GUILD, join.discord, TOKEN, function(roles, problem)
if not roles then
AnswerPlayerJoin(ask, false, problem == "not a member" and "Join our Discord first." or "Your roles could not be checked - try again.")
return
end
for _, role in ipairs(roles) do
if role == ROLE then AnswerPlayerJoin(ask, true) return end
end
AnswerPlayerJoin(ask, false, "You do not have the Whitelisted role in our Discord.")
end)
end

OnPlayerJoinRequest · AnswerPlayerJoin · GetPlayerDiscordId · HttpRequest · the Joins and Discord group of the index