Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
566 views
in Technique[技术] by (71.8m points)

c# - discord webhook messages keep duplicating

Im making a webhook sender GUI with C#, and it mostly works fine. The one issue i cant figure out how to fix is this:image

the first time I press the send button, it works fine. but every time I press it after that the username and text gets sent an extra time, and the pfp of the message gets removed. I don't get it. heres the main webhook code:

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();
    }

    
}

heres the gui code:

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);
            
        }
    }
}

here is an image of the GUI: GUIimage


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...