[Tutorial] Discord PM system
#1

hello all
Disclaimer : this method I explored alone in a test server in ultra-h and it won't be existing in another gamemode and if it is ,we're thinking same way and i don't might annoy anyone who does like me .

here we start

first add this in top of script .
Code:
new DCC_Channel:PmedChannel[MAX_PLAYERS];
new PmedUser[32][MAX_PLAYERS];
this store channel of DiscordUser That pmed Bot that is connected to server in a DM channel so we could pm back ,and store name too

now let's add this function to pm any channel easly but we'll pm DM channel
Code:
stock SendMessageToChannel(ChannelId[],const string[])
{
	#if defined dcconnector_included
		new DCC_Channel:TargetChannel;
		if (_:TargetChannel == 0)
		TargetChannel = DCC_FindChannelById(ChannelId); // Discord channel ID
		DCC_SendChannelMessage(TargetChannel, string);
	#else
		format(ChannelId,36,"rgtsd %s",string); // to not get stupid warnnings (non effectable)
	#endif
	return 1;
}
you don't need to focus in this code alot
main part is the callback

Code:
public DCC_OnChannelMessage(DCC_Channel:channel, DCC_User:author, const message[])
{
	new channel_name[100],DCC_ChannelType:type,user_name[32],idaw[3],dest[128],bool:is_bot;

	if(!DCC_GetChannelName(channel, channel_name)) return 0; // invalid channel
	if (!DCC_GetUserName(author, user_name)) return 0; // invalid user
	DCC_GetChannelId(DCC_Channel:channel, dest); new chann = strval(dest); // getting channel id to pm back channel easly
	DCC_GetUserId(DCC_User:author, idaw); new userid = strval(idaw); // for security stuffs
	DCC_IsUserBot(DCC_User:author, is_bot); // to avoid bot spam and rate limit .
    DCC_GetChannelType(DCC_Channel:channel, DCC_ChannelType:type); // getting channel type and if type is 1 the channel type is DM is when you pm the bot especially
 	if(!is_bot)
  	{
        switch(type)
	    {
			case 1:
			{
			    new pmstring[256];
				new xTempCMD[16], xTempCMD2[256],xTempCMD3[256];
				sscanf(message[1], "s[16]s[3]s[256]", xTempCMD, xTempCMD2, xTempCMD3);// ah you need sscanf between
				if(message[0] = "/")
				{
					if(!strcmp(xTempCMD, "pm", true))// checking if you insert '/pm'
					{
						new id = strval(xTempCMD2); // getting second params 'id'
						if(IsPlayerConnected(id))//checking if player connected
						{
						    if(pInfo[id][pLogged] == 1) //something like this if player logged in his acc ,you can delete it if you want
							{
								if(pAcc[id][Blockpm] == 0) // check if the tarjet players blocking his pm ,you may delete or change it like your script
								{
									format(pmstring,sizeof(pmstring),"{007AFF}[Discord]{faf000} PM From {fcf111}%s(%i): {faf000}%s",user_name,userid,xTempCMD3);// sending message to player
									SendClientMessage(id,-1,pmstring);
									PmedChannel[id] = channel ; //stoting channel .
									format(PmedUser[id],128,"%s",user_name); //storing name
								}
								SendMessageToChannel(dest,"[BrainBot] : Requested Player Is Blocking Pms"); // back a message
							}
							SendMessageToChannel(dest,"[BrainBot] : Requested Player didn't Log In Yet"); // obvious
						}
						SendMessageToChannel(dest,"[BrainBot] : Requested Player Is not connected"); // obvious
		        	}
	        	}
			}
	    }
	}
	return 1;
}
i think i explained there everything .
now we finished
wops forget responding command ,my fault

Code:
CMD:r(playerid,params[])
{
	if(pInfo[playerid][pLogged] == 1)
	{
		new message[256],pmstring[256];
		if(sscanf(params,"s[256]", message)) return SendClientMessage(playerid,-1,"{0F0F0F}[SYNTAX]:{FF1111}/pm [playerid] [message]");//sscanf of course :D
		if(pInfo[playerid][pLogged] == 1)
		{
				#if defined dcconnector_included
			    new stringme[256],dest[128];

			    format(stringme,sizeof(stringme),"[PM] Reply From %s(%i): %s",PlayerName(playerid),playerid,message);
			    DCC_GetChannelId(PmedChannel[playerid], dest);
				SendMessageToChannel(dest, stringme);// backing message to channel
						
			    format(pmstring,sizeof(pmstring),"{007AFF}[Discord]{faf000} PM To {fcf111}%s : {faf000}%s",PmedUser[playerid],message);
				SendClientMessage(playerid,-1,pmstring); // showing what player wronte in the message
			#endif
		}
	}
	return 1;
}
please rep my work and feedback if you got any problem ,remember its pain in ass to upload test to server and doing this took time ,so reps me
Reply
#2

Nice man , thanks for the tutorial I was looking for this
Reply
#3

GJ. Thx bro.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)