Vb.net在discord webhook上发送消息
我想从我的Vb.net应用程序向discord服务器发送一条消息,但我不知道确切的方法,这是我的代码Vb.net在discord webhook上发送消息,vb.net,discord,webhooks,Vb.net,Discord,Webhooks,我想从我的Vb.net应用程序向discord服务器发送一条消息,但我不知道确切的方法,这是我的代码 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Using x As New HttpRequest x.KeepAlive = True x.IgnoreProtocolErrors = True
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Using x As New HttpRequest
x.KeepAlive = True
x.IgnoreProtocolErrors = True
x.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.3"
x.Cookies = New CookieDictionary(False)
Dim dis As String = x.Post("https://discordapp.com/api/webhooks/681417452596232216/blahblahblahbsamplesample", String.Concat(New String() {"{""content"":", TextBox1.Text, "}"}), "application/json").ToString()
End Using
End Sub
当使用服务器和链接时,请考虑使用C**。我无法测试您的代码,因为您尚未指定是否使用自定义类
但是如果你坚持使用VB.NET发送不和谐的Web钩子,我发现了一个在VB.NET中创建的精确项目。在这里查看: 如果要将此项目切换到C#,则必须创建一个类using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace SendWebHook_Test
{
class Http
{
public static byte[] Post(string uri,
NameValuecollection pairs)
{
using (webClient= new WebClient())
return WebClient.UploadValues(uri, pairs);
}
}
}
我们使用相同的方法WebClient。但在本例中,我们有3个文本框控件
- 指定URL的TextBox1
- 显示名称的文本框2
- 消息的文本框3
- 还有一个按钮
public static void sendWebHook(string URL, string msg,
string username)
{
Http.post(URL, new NameValueCollection()
{
{
"username",
username
},
{
"content",
msg
}
});
}
private void button1_Click(object sender, EventArgs e)
{
sendWebHook(textBox1.Text, textBox2.Text, textBox3.Text);
}
希望我已经回答了你的问题,我很难用不和谐来测试这个问题。请原谅我的任何缺陷。这可能是一个很好的答案,但问题被标记为vb.net。如果您正在寻找该项目的vb.net版本,请参阅我的答案开头我引用了一个名为Discord Webhook Announcer的项目。再次尝试使用C#,但是最好。对不起,我没有仔细阅读你的答案,因为我不熟悉不和谐。我刚注意到C代码。为什么你说C#更适合服务器和链接?因为C#支持并参与了XML-RPC,这是一种远程过程协议。我也无法想象VB.NET在网络编程中的应用。但这是可能的,请参阅Microsoft的文档: