Raised This Month: $ Target: $400
 0% 

Discord GetGuildMember how to process?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
xerox8521
Senior Member
Join Date: Sep 2011
Old 07-20-2023 , 13:37   Discord GetGuildMember how to process?
Reply With Quote #1

Hi,
using this plugin https://forums.alliedmods.net/showthread.php?t=292448 and I wanted to add a way to retrieve the guild specific Nickname for a given user now there is GetGuildMember in the Discord API but I'm not familiar enough with the plugin nor Discords API to know how I'm supposed to return a DiscordGuildUser object.

native is supposed to look something like
PHP Code:
native DiscordGuildUser GetGuildMemberByUserID(char[] userID); 
What I tried is basically replicating what the existing code does but I don't fully know how to proceed.

Native is implemented as
PHP Code:
public int Native_DiscordBot_GetBuildMemberByUser(Handle pluginint numParams)
{
    
DiscordBot bot view_as<DiscordBot>(CloneHandle(GetNativeCell(1)));
    
char guild[32];
    
GetNativeString(2guildsizeof(guild));
    
char userID[32];
    
GetNativeString(3userIDsizeof(userID));

    
Handle hData json_object();
    
json_object_set_new(hData"bot"bot);
    
json_object_set_new(hData"guild"guild);
    
json_object_set_new(hData"user"userID);

    
Handle fwd CreateForward(ET_IgnoreParam_CellParam_StringParam_Cell);
    
AddToForward(fwdpluginfCallback);
    
json_object_set_new(hData"callback"json_integer(view_as<int>(fwd)));
    
GetMember(hData);
    return 
1;

GetMember has this implementation:
PHP Code:
static void GetMember(Handle hData) {
    
DiscordBot bot view_as<DiscordBot>(json_object_get(hData"bot"));
    
    
char guild[32];
    
JsonObjectGetString(hData"guild"guildsizeof(guild));
    
    
int limit JsonObjectGetInt(hData"limit");
    
    
char userID[32];
    
JsonObjectGetString(hData"userID"userIDsizeof(userID));
    
    
char url[256];
    
    
FormatEx(urlsizeof(url), "https://discord.com/api/guilds/%s/members/%s"guilduserID);
    
    
char route[128];
    
// I don't even know if this is correct or anything
    
FormatEx(routesizeof(route), "guild/%s/members/%s"guilduserID);
    
    
DiscordRequest request = new DiscordRequest(urlk_EHTTPMethodGET);
    if(
request == null) {
        
delete bot;
        
CreateTimer(2.0SendGetMemberhData);
        return;
    }
    
request.SetCallbacks(HTTPCompletedMemberDataReceive);
    
request.SetBot(bot);
    
request.SetData(hDataroute);
    
    
request.Send(route);
    
    
delete bot;

Member Data is declared as
PHP Code:
public MemberDataReceive(Handle requestbool failureint offsetint statuscodeany dp) {
    if(
failure || (statuscode != 200)) {
        if(
statuscode == 400) {
            
PrintToServer("BAD REQUEST");
        }
        
        if(
statuscode == 429 || statuscode == 500) {
            
GetMembers(dp);
            
            
delete request;
            return;
        }
        
LogError("[DISCORD] Couldn't Send GetMember - Fail %i %i"failurestatuscode);
        
delete request;
        
delete view_as<Handle>(dp);
        return;
    }
    
SteamWorks_GetHTTPResponseBodyCallback(requestGetMemberDatadp);
    
delete request;

GetMemberData declaration:
PHP Code:
public int GetMemberData(const char[] dataany dp) {
    
Handle hJson json_load(data);
    
Handle hData view_as<Handle>(dp);
    
DiscordBot bot view_as<DiscordBot>(json_object_get(hData"bot"));
    
    
Handle fwd view_as<Handle>(JsonObjectGetInt(hData"callback"));
    
    
char guild[32];
    
JsonObjectGetString(hData"guild"guildsizeof(guild));
    
json_object
    
    
if(fwd != null) {
        
Call_StartForward(fwd);
        
Call_PushCell(bot);
        
Call_PushString(guild);
        
Call_PushCell(hJson);
        
Call_Finish();
    }
    
    
delete bot;
    if(
JsonObjectGetBool(hData"autoPaginate")) {
        
int size json_array_size(hJson);
        
int limit JsonObjectGetInt(hData"limit");
        if(
limit == size) {
            
Handle hLast json_array_get(hJsonsize 1);
            
char lastID[32];
            
json_string_value(hLastlastIDsizeof(lastID));
            
delete hJson;
            
delete hLast;
            
            
json_object_set_new(hData"afterID"json_string(lastID));
            
GetMembers(hData);
            return 
1;
        }
    }
    
    
delete hJson;
    
delete hData;
    
delete fwd;
    return 
0;


Doing it manually be retrieving all Guild Members does not work as I'm getting this error when attempt to retrieve the guild members list:
PHP Code:
L 07/20/2023 17:18:40: [SMException reportedNot enough space on the heap
L 07
/20/2023 17:18:40: [SMBlamingdiscord_api.smx
L 07
/20/2023 17:18:40: [SMCall stack trace:
L 07/20/2023 17:18:40: [SM]   [0SteamWorks_GetHTTPResponseBodyCallback
L 07
/20/2023 17:18:40: [SM]   [1Line 117discord\GuildMembers.sp::MembersDataReceive 
xerox8521 is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 09:26.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode