Hi, My discord bot sends a message to each new guild member when they join. I have a issue when trying to pass german or russian characters it gives a bad request but it works fine with english. Maybe a UTF 8 issue? I test with postman and it's all fine in postman. See code below and attachment.
Content that fails to send:
AND
![f1HP0W7ILG.png](https://www.esegece.com/index.php?option=com_easydiscuss&controller=attachment&task=download&tmpl=component&id=47)
Content that fails to send:
{
"content": "[DE] Willkommen zum Offiziellen RSMfmx Discord. Um unseren Discord Server nutzen zu können, müssen wir uns zunächst vergewissern, dass Sie ein Kunde sind. Bitte antworten Sie auf diesen Bot nur mit Ihrem Lizenzschlüssel."
}
AND
{
"content": "[RUS] Добро пожаловать в официальный Discord RSMfmx. Прежде чем Вы начнёте использовать наш сервер Discord, нам нужно убедиться, что Вы являетесь нашим клиентом. Пожалуйста, ответьте этому боту указав свой лицензионный ключ."
}
procedure TdmComponents.OnGuildMemberAdd(const aText: string);
begin
try
var jdata := TdJSON.Parse(aText);
try
var member: TGuildMember;
member.Username := jdata['d']['user']['username'].AsString;
member.PublicFlags := jdata['d']['user']['public_flags'].AsInteger;
member.ID := jdata['d']['user']['id'].AsString;
member.Discriminator := jdata['d']['user']['discriminator'].AsString;
member.JoinedAt := jdata['d']['joined_at'].AsString;
var aChannelID := '';
var jdm := TdJSON.Parse(discordAPI.POST_Request('/users/@me/channels', '{"recipient_id": "' + member.ID + '"}'));
var msges := TStringList.Create;
try
msges.LoadFromFile('.\msg\join.txt', TEncoding.UTF8);
aChannelID := jdm['id'].AsString;
for var msg in msges do
begin
var StringWriter := TStringWriter.Create();
var Writer := TJsonTextWriter.Create(StringWriter);
Writer.Formatting := TJsonFormatting.Indented;
with Writer do
begin
WriteStartObject;
WritePropertyName('content');
WriteValue(msg);
WriteEndObject;
end;
Writeln(StringWriter.ToString);
discordAPI.POST_Request('/channels/' + aChannelID + '/messages', StringWriter.ToString);
Writer.Free;
StringWriter.Free;
end;
finally
msges.Free;
jdm.Free;
end;
finally
jdata.Free;
end;
except
on E: Exception do
begin
Writeln(E.Message);
end;
end;
end;