我正在用 C# 制作一个 webhook 发送者 GUI,并且它大部分工作正常。我无法弄清楚如何解决的一个问题是:image
我第一次按下发送按钮时,它工作正常。但是每次我按下它之后,用户名和文本都会额外发送一次,并且消息的 pfp 被删除。我不明白。 这是主要的网络钩子代码:
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
public class dWebHook : IDisposable
{
private readonly WebClient dWebClient;
private static NameValueCollection discordValues = new NameValueCollection();
public string WebHook { get; set; }
public string UserName { get; set; }
public string ProfilePicture { get; set; }
public dWebHook()
{
dWebClient = new WebClient();
}
public void SendMessage(string msgSend)
{
discordValues.Add("username", UserName);
discordValues.Add("avatar_url", ProfilePicture);
discordValues.Add("content", msgSend);
dWebClient.UploadValues(WebHook, discordValues);
}
public void Dispose()
{
dWebClient.Dispose();
}
}
这里是gui代码:
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ZP_webhook_spammer
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Button1_Click(object sender, EventArgs e)
{
using dWebHook dcWeb = new dWebHook
{
ProfilePicture = PFPBox3.Text,
UserName = UsernameBox2.Text,
WebHook = WebhookBox1.Text
};
dcWeb.SendMessage(MessageBox1.Text);
}
}
}
这是图形用户界面的图像: GUIimage