[英]How can I send a POST request to Discord Webhooks C#
所以我正在制作一個 FiveM 資源,它會收到一條消息,然后將其發送到 Discord 頻道。 我需要它是服務器端腳本。
我試過使用 WebClient、Flurl.Http 和一些異步、等待的東西,但它們都不起作用
我試過這個 WebClient
using (var wb = new WebClient())
{
string content = message;
string username = "" + name + "(ID: )" + id;
var data = new NameValueCollection();
data["username"] = username;
data["content"] = content;
var response = wb.UploadValues(discordURL, "POST", data);
string responseInString = Encoding.UTF8.GetString(response);
Debug.WriteLine(responseInString);
}
我試過使用異步,用字典等待
var values = new Dictionary<string, string>
{
{ "username", name + " ID: " + id },
{ "content", message }
};
var content = new FormUrlEncodedContent(values);
var response = await client.PostAsync(discordURL, content);
var responseString = await response.Content.ReadAsStringAsync();
最后一次,我嘗試使用 Flurl.Http
var responseString = await discordURL
.PostUrlEncodedAsync(new { username = name + " ID: " + id, content = message })
.ReceiveString();
Flurl.Http 使用返回時,無法找到依賴項,而其他依賴項只是滯后於整個 FiveM 聊天資源並且不執行任何操作。
如果你能幫助我,那就最好了,謝謝。
如果您想從您的 FiveM 服務器向您的 Discord 網絡掛鈎發送消息,請嘗試使用此本機功能。
PerformHttpRequest('discord web-hook link', function(Error, Content, Head) end, 'POST', json.encode({username = 'bot user name', content = 'message'}), { ['Content-Type'] = 'application/json' })
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.