Advertisement
agentsix1

Jeremy-Demo Discord Bot

Jul 26th, 2017
40,390
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 3.36 KB | None | 0 0
  1. Imports Discord
  2. Public Class Form1
  3.     Dim html = ""
  4.     Dim bot_token = ""
  5.     Dim WithEvents discord As New DiscordClient
  6.     Private Sub TextBox1_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyDown
  7.         If e.KeyCode = Keys.Enter Then
  8.             sendMessage(TextBox1.Text)
  9.             TextBox1.Text = ""
  10.         End If
  11.     End Sub
  12.  
  13.     Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
  14.         If CheckBox1.CheckState = CheckState.Checked Then
  15.             Timer1.Enabled = True
  16.         Else
  17.             Timer1.Enabled = False
  18.         End If
  19.     End Sub
  20.  
  21.     Public Sub connect()
  22.         discord.Connect(bot_token, TokenType.Bot)
  23.     End Sub
  24.  
  25.     Public Sub disconnect()
  26.         discord.Disconnect()
  27.     End Sub
  28.  
  29.     Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  30.         Try
  31.             disconnect()
  32.             addLine("<font color=red>Disconnected</font></br>")
  33.         Catch ex As Exception
  34.             addLine("<font color=red>Failed to disconnect...</font></br>")
  35.         End Try
  36.  
  37.     End Sub
  38.  
  39.     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  40.         Try
  41.             connect()
  42.             addLine("<font color=lime>Connected!</font></br>")
  43.         Catch ex As Exception
  44.             addLine("<font color=red>Failed to connect...</font></br>")
  45.         End Try
  46.  
  47.     End Sub
  48.  
  49.     Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
  50.         If discord.State = ConnectionState.Connected Or discord.State = ConnectionState.Connecting Then
  51.             e.Cancel = True
  52.             MsgBox("Disconnect your bot before closing.")
  53.         End If
  54.     End Sub
  55.  
  56.     Public Sub addLine(msg As String)
  57.         html = html & "<font color=grey><</font><font color=orange>" & DateTime.Now.ToString("HH:mm:ss") & "</font><font color=grey>></font> " & msg
  58.         System.IO.File.WriteAllText(Application.StartupPath & "\test.html", html)
  59.         WebBrowser1.Navigate(Application.StartupPath & "\test.html")
  60.     End Sub
  61.  
  62.     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  63.         html = "<body bgcolor=black>"
  64.         addLine("<font color=pink>Discord Chat Bot (Demo) v0.1</font><br>")
  65.         addLine("<font color=yellow>Made By: Agentsix1 (7-26-17)</font><br>")
  66.         addLine("<font color=white>---------------------------------------------------</font><br>")
  67.     End Sub
  68.  
  69.     Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
  70.         WebBrowser1.Document.Window.ScrollTo(0, 1000000000)
  71.     End Sub
  72.  
  73.     Public Sub sendMessage(msg As String)
  74.         Try
  75.             discord.FindServers("test server").FirstOrDefault().FindChannels(ComboBox1.Text).FirstOrDefault().SendMessage(msg)
  76.         Catch ex As Exception
  77.  
  78.         End Try
  79.     End Sub
  80.  
  81.     Public Sub onMessageEvent(sender As Object, e As Discord.MessageEventArgs) Handles discord.MessageReceived
  82.         Dim message = e.Message.RawText
  83.         Dim username = e.User.Name
  84.         Dim channel = e.Channel.Name
  85.         addLine("<font color=grey><</font><font color=green>" & channel & "</font><font color=grey>> <</font><font color=purple>" & username & "</font><font color=grey>></font> <font color=white>" & message & "</font><br>")
  86.     End Sub
  87.  
  88. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement