Advertisement
literallycj

VB.net Discord Webhook sender

Jun 30th, 2019
709
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.59 KB | None | 0 0
  1. 'I haven't seen much of these for VB.net, so here's something I made...
  2. 'Please note that I am a beginner, so some things may be able to be optimised.
  3. 'However, this does work very fast.
  4.  
  5. Imports System.Collections.Specialized
  6. Imports System.Net
  7.  
  8. Module Module1
  9.  
  10.     Public Class dWebHook
  11.         Implements IDisposable
  12.  
  13.         Private ReadOnly dWebClient As WebClient
  14.         Private Shared discordValues As NameValueCollection = New NameValueCollection()
  15.         Public Property WebHook As String
  16.         Public Property UserName As String
  17.         Public Property ProfilePicture As String
  18.  
  19.         Public Sub New()
  20.             dWebClient = New WebClient()
  21.         End Sub
  22.  
  23.         Public Sub SendMessage(ByVal msgSend As String)
  24.  
  25.             discordValues.Add("username", UserName)
  26.             discordValues.Add("avatar_url", ProfilePicture)
  27.             discordValues.Add("content", msgSend)
  28.  
  29.             dWebClient.UploadValues(WebHook, discordValues)
  30.  
  31.             discordValues.Remove("username")
  32.             discordValues.Remove("avatar_url")
  33.             discordValues.Remove("content")
  34.         End Sub
  35.  
  36.         Public Sub Dispose()
  37.             dWebClient.Dispose()
  38.         End Sub
  39.  
  40.         Private Sub IDisposable_Dispose() Implements IDisposable.Dispose
  41.             DirectCast(dWebClient, IDisposable).Dispose()
  42.         End Sub
  43.     End Class
  44.  
  45.     Sub Main()
  46.  
  47.         Dim username, webhook, message
  48.  
  49.         Try
  50.             Console.WriteLine("")
  51.             Console.WriteLine("Please link your webhook here.")
  52.             Console.WriteLine("Example: https://discordapp.com/api/webhooks/longlistofnumbersandletters")
  53.  
  54.             webhook = Console.ReadLine()
  55.             Console.Clear()
  56.  
  57.             Console.WriteLine("")
  58.             Console.WriteLine("Please write the name you want your webhook to have.")
  59.             Console.WriteLine("Example: 'dave'")
  60.  
  61.             username = Console.ReadLine
  62.             Console.Clear()
  63.  
  64.             Console.WriteLine("")
  65.             Console.WriteLine("Please write the message you wish to send.")
  66.             Console.WriteLine("Example: 'Hello world!'")
  67.  
  68.             message = Console.ReadLine
  69.             Console.Clear()
  70.  
  71.             Dim dcWeb As dWebHook = New dWebHook
  72.             dcWeb.UserName = username
  73.             dcWeb.WebHook = webhook
  74.             dcWeb.SendMessage(message)
  75.  
  76.             Console.ReadLine()
  77.  
  78.         Catch ex As System.ArgumentException
  79.             Console.WriteLine("Error. Please use the examples provided for guidance.")
  80.             Console.ReadLine()
  81.         End Try
  82.  
  83.     End Sub
  84. End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement