My bot sends an embed message to a specific channel, after that it automatically ads a reaction to the message.
Examples: "😊" and "😂"
Button to send the embed: (works fine)
Private Async Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim embed As New EmbedBuilder With {
.ThumbnailUrl = discord.CurrentUser.GetAvatarUrl,
.Title = "Just title.",
.Description = "Enjoy",
.Color = New Discord.Color(255, 0, 0)
}
discord.GetGuild("12345..").GetTextChannel("54321..").SendMessageAsync("", False, embed)
End Sub
Now how to make it add the two reactions after the message is sent? ("😊" and "😂")
I figured out that it could work with the message received handler, here's what I tried. (I'm not sure if it works)
Private Async Function onMsg(message As SocketMessage) As Task
If message.Source = MessageSource.Bot Then
Dim reaction As SocketReaction
Dim rMessage = CType(Await message.Channel.GetMessageAsync(message.Id), RestUserMessage)
If reaction.Emote.Name.Equals("😊") AndAlso
reaction.Emote.Name.Equals("😂")
Else
Dim my_emo1 As Emoji = ("😊")
Dim my_emo2 As Emoji = ("😀")
rMessage.AddReactionAsync(my_emo1)
rMessage.AddReactionAsync(my_emo2)
End If
End Function
Using your current code:
Private Async Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim embed As New EmbedBuilder With {
.ThumbnailUrl = discord.CurrentUser.GetAvatarUrl,
.Title = "Just title.",
.Description = "Enjoy",
.Color = New Discord.Color(255, 0, 0)
}
Dim msg = Await discord.GetGuild("12345..").GetTextChannel("54321..").SendMessageAsync(embed:=embed.Build)
Dim my_emo1 As New Emoji("😊")
Dim my_emo2 As New Emoji("😀")
Await msg.AddReactionAsync(my_emo1)
Await msg.AddReactionAsync(my_emo2)
End Sub
Related
Im doing exactly the same as in this question:
How can I call MapLocationFinder.FindLocationsAsync() to get the coordinates for an address without already knowing the latitude and longitude?
However my result.locations list keeps running into an error while result.status is success
Private Async Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim addressToGeocode As String = "Microsoft"
Dim queryHint As New BasicGeoposition With {.Latitude = 47.643, .Longitude = -122.131}
Dim hintPoint As New Geopoint(queryHint)
Dim result As MapLocationFinderResult = Await MapLocationFinder.FindLocationsAsync(addressToGeocode, hintPoint, 3)
If result.Status = MapLocationFinderStatus.Success Then
Dim test = result.Locations(0) 'xxx
End If
End Sub
"No type information for MapGeocoder.dll"
Have you any helpful references for this?
I was testing the example by microsoft https://learn.microsoft.com/en-us/windows/uwp/maps-and-location/geocoding
This code should give me a simple output (result = (47.6406099647284,-122.129339994863))
However I get an out of range exception on result.Locations(0). So I dont get any locations in my result.
Private Async Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim addressToGeocode As String = "Microsoft"
Dim queryHint As New BasicGeoposition With {.Latitude = 47.643, .Longitude = -122.131}
Dim hintPoint As New Geopoint(queryHint)
Dim result As MapLocationFinderResult = Await MapLocationFinder.FindLocationsAsync(addressToGeocode, hintPoint, 3)
If result.Status = MapLocationFinderStatus.Success Then
Dim test = result.Locations(0)
Label1.Text = $"result = ({result.Locations(0).Point.Position.Latitude},{result.Locations(0).Point.Position.Longitude})"
End If
End Sub
If I try to debug native code I get an error "MapGeocoder.pdb could not be loaded". I dont know if this causes the same trouble with the locations.
Using Microsoft.AspNet.Identity i have almost all I need to manage the users problems, but I ( a vb.net beginner) can't update this code to automatically sign in the user when he confirm the email address.
I think I need a method to get ApplicationUser just based on UsedId
This is the code I try to change:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim code As String = IdentityHelper.GetCodeFromRequest(Request)
Dim userId As String = IdentityHelper.GetUserIdFromRequest(Request)
If code IsNot Nothing AndAlso userId IsNot Nothing Then
Dim manager = Context.GetOwinContext().GetUserManager(Of ApplicationUserManager)()
Dim result = manager.ConfirmEmail(userId, code)
If result.Succeeded Then
'>>>>>>>>login the user
successPanel.Visible = True
Return
End If
End If
successPanel.Visible = False
errorPanel.Visible = True
End Sub
In case someone else have this issue, this is the code i used
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim code As String = IdentityHelper.GetCodeFromRequest(Request)
Dim userId As String = IdentityHelper.GetUserIdFromRequest(Request)
If code IsNot Nothing AndAlso userId IsNot Nothing Then
Dim manager = Context.GetOwinContext().GetUserManager(Of ApplicationUserManager)()
Dim result = manager.ConfirmEmail(userId, code)
If result.Succeeded Then
Try
Dim task = New UserStore(Of Sue.ApplicationUser)(Context.GetOwinContext().[Get](Of ApplicationDbContext)()).FindByIdAsync(userId)
Dim user = task.Result()
Dim signInManager = Context.GetOwinContext().Get(Of ApplicationSignInManager)()
signInManager.SignIn(user, isPersistent:=False, rememberBrowser:=False)
Context.Response.Redirect("/Account/UserData", False)
Catch ex As Exception
successPanel.Visible = False
errorPanel.Visible = True
Return
End Try
End If
End If
successPanel.Visible = False
errorPanel.Visible = True
End Sub
I have a data repeater that contains a PictureBox and the picture needs to be fetched from a webserver. I already have a function that downloads the image, but the binding does not seem to be working. I am quite new to using windows forms and I am not too sure what I am doing wrong.
I have tried using a gridview, and I can confirm that that does show the images.
Public Function DlImg(ByVal _URL As String) As Byte()
Dim _tmpImage As Image = Nothing
Dim BytesOut As Byte()
Try
Dim _HttpWebRequest As System.Net.HttpWebRequest = DirectCast(System.Net.HttpWebRequest.Create(_URL), System.Net.HttpWebRequest)
_HttpWebRequest.AllowWriteStreamBuffering = True
Dim _WebResponse As System.Net.WebResponse = _HttpWebRequest.GetResponse():
Dim _WebStream As System.IO.Stream = _WebResponse.GetResponseStream()
_tmpImage = Image.FromStream(_WebStream)
_WebResponse.Close()
Using picture As Image = _tmpImage
Using stream As New IO.MemoryStream
picture.Save(stream, Imaging.ImageFormat.Jpeg)
BytesOut = stream.GetBuffer()
End Using
End Using
Catch _Exception As Exception
Return Nothing
End Try
Return BytesOut
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ListData.Columns.Add("Image", Type.GetType("System.Byte[]"))
For Each row As DataRow In ListData.Rows
row("Image") = DlImg("http://rental.joshblease.co.uk/propertyimages/p184js94kv1qco1e1e1jt71ouv11lm6.jpg")
Next row
ImgListItem.DataBindings.Add("Image", ListData, "Image", True)
DataGridView1.DataSource = ListData
DataRepeater1.DataSource = ListData
End Sub
I am trying to create an updater for my program which automatically download's the latest version of my program from the web. Now I want this process to be done using a progress bar (so when the download progress is at 50% the progress bar is half-way through). This is my code:
Private Sub client_ProgressChanged(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs)
Dim bytesIn As Double = Double.Parse(e.BytesReceived.ToString())
Dim totalBytes As Double = Double.Parse(e.TotalBytesToReceive.ToString())
Dim percentage As Double = bytesIn / totalBytes * 100
client.Value = Int32.Parse(Math.Truncate(percentage).ToString())
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim url As String = "MY DOWNLOAD LINK"
'Download
Dim client As WebClient = New WebClient
AddHandler client.DownloadProgressChanged, AddressOf client_ProgressChanged
AddHandler client.DownloadFileCompleted, AddressOf client_DownloadCompleted
client.DownloadFileAsync(New Uri(url), "C:\Users\User\Desktop\BACKUP\TESTING\New folder\1.exe")
End Sub
End Class
Now I know that the place where the file is saved has been inputed manually by me , but I will change that later. My problem currently is that the file is not being downloaded. However when I change the DownloadFileAsync method to DownloadFile , my program downloads the file. However with the DownloadFile method I will not be able to use the progress bar to track the download progress. Any help is much appreciated :-)
Don't know what you mean, when you say that the file isn't downloaded? You get an Error/Exception? Nothing happens at all? Did you place breakpoints, debug.prints etc?
With VS2012 and asyn/await you can put everything into one method an keep a "linear code-flow". Import System.Threading and System.Threading.Tasks
Private Async Function DownloadWithProgress(ByVal url As String, ByVal p As ProgressBar) As Task(Of Integer)
Dim wc As Net.HttpWebRequest = DirectCast(Net.HttpWebRequest.Create(url), Net.HttpWebRequest)
Dim resp = Await (New TaskFactory(Of Net.WebResponse)).StartNew(AddressOf wc.GetResponse)
p.Value = 0
p.Maximum = CInt(resp.ContentLength)
Dim rqs = resp.GetResponseStream
Dim bufsize As Integer = 1 << 16
Dim buffer(bufsize) As Byte
Dim got As Integer = 0
Dim total As Integer = 0
Do
got = Await (New TaskFactory(Of Integer)).FromAsync(AddressOf rqs.BeginRead, AddressOf rqs.EndRead, buffer, 0, bufsize, Nothing)
total += got
Me.Label1.Text = "got: " & total.ToString
p.Increment(got)
Loop Until got = 0
Return total
End Function
In this sample, the data from the web is downloaded into an array, but you can of course also write it into a file, or do whatever you want with the data.
Sample for usage:
Private running As Boolean = False
Private Async Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
If running Then
MessageBox.Show("Cant you see, I'm working?")
Exit Sub
Else
running = True
End If
Await DownloadWithProgress("http://download.thinkbroadband.com/5MB.zip", ProgressBar1)
running = False
End Sub