Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports Discord
- Public Class Form1
- Dim html = ""
- Dim bot_token = ""
- Dim WithEvents discord As New DiscordClient
- Private Sub TextBox1_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyDown
- If e.KeyCode = Keys.Enter Then
- sendMessage(TextBox1.Text)
- TextBox1.Text = ""
- End If
- End Sub
- Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
- If CheckBox1.CheckState = CheckState.Checked Then
- Timer1.Enabled = True
- Else
- Timer1.Enabled = False
- End If
- End Sub
- Public Sub connect()
- discord.Connect(bot_token, TokenType.Bot)
- End Sub
- Public Sub disconnect()
- discord.Disconnect()
- End Sub
- Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
- Try
- disconnect()
- addLine("<font color=red>Disconnected</font></br>")
- Catch ex As Exception
- addLine("<font color=red>Failed to disconnect...</font></br>")
- End Try
- End Sub
- Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
- Try
- connect()
- addLine("<font color=lime>Connected!</font></br>")
- Catch ex As Exception
- addLine("<font color=red>Failed to connect...</font></br>")
- End Try
- End Sub
- Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
- If discord.State = ConnectionState.Connected Or discord.State = ConnectionState.Connecting Then
- e.Cancel = True
- MsgBox("Disconnect your bot before closing.")
- End If
- End Sub
- Public Sub addLine(msg As String)
- html = html & "<font color=grey><</font><font color=orange>" & DateTime.Now.ToString("HH:mm:ss") & "</font><font color=grey>></font> " & msg
- System.IO.File.WriteAllText(Application.StartupPath & "\test.html", html)
- WebBrowser1.Navigate(Application.StartupPath & "\test.html")
- End Sub
- Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- html = "<body bgcolor=black>"
- addLine("<font color=pink>Discord Chat Bot (Demo) v0.1</font><br>")
- addLine("<font color=yellow>Made By: Agentsix1 (7-26-17)</font><br>")
- addLine("<font color=white>---------------------------------------------------</font><br>")
- End Sub
- Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
- WebBrowser1.Document.Window.ScrollTo(0, 1000000000)
- End Sub
- Public Sub sendMessage(msg As String)
- Try
- discord.FindServers("test server").FirstOrDefault().FindChannels(ComboBox1.Text).FirstOrDefault().SendMessage(msg)
- Catch ex As Exception
- End Try
- End Sub
- Public Sub onMessageEvent(sender As Object, e As Discord.MessageEventArgs) Handles discord.MessageReceived
- Dim message = e.Message.RawText
- Dim username = e.User.Name
- Dim channel = e.Channel.Name
- 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>")
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement