15.02.2019, 19:22
(
Last edited by iamjems; 16/02/2019 at 12:29 AM.
)
Replacing Discord mentions with the mentioned user's (nick)name
NOTE: dc_Guild must be the ID of your guild (Discord server).
PHP Code:
ReplaceDiscordMentions(const message[])
{
new DCC_User:mention_id,
mention_name[33],
user[19],
string[166],
pos;
format(string, sizeof(string), message);
for(new i; i < sizeof(string); i++)
{
if(string[i] == '<' && string[i + 1] == '@')
{
pos = i;
if(string[i + 2] == '!')
i++;
strmid(user, string, i + 2, i + 21);
mention_id = DCC_FindUserById(user);
if(!mention_id)
continue;
DCC_GetGuildMemberNickname(dc_Guild, mention_id, mention_name);
if(isnull(mention_name))
DCC_GetUserName(mention_id, mention_name);
format(mention_name, sizeof(mention_name), "@%s", mention_name);
strdel(string, pos, pos + 21 + (i - pos));
strins(string, mention_name, pos);
}
}
return string;
}
PHP Code:
public DCC_OnChannelMessage(DCC_Channel:channel, DCC_User:author, const message[])
{
if(channel == yourDiscordChannel)
{
SendClientMessageToAll(-1, ReplaceDiscordMentions(message));
}
return 1;
}
hello <@172459264917204728>
OR
hello <@!172459264917204728>
to this:
hello @John