I am trying to delete a discord message using discordgo. Currently I have the ping pong example, however instead of writing a message I want to delete the message.
I have currently got this far:
func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
if m.Author.ID == s.State.User.ID || m.Author.Bot {
return
}
if m.Content == "ping" {
s.ChannelMessageDelete(m.ChannelID, m.ID)
}
}
But the implementation does not delete the message even though other code in the block will run. I am a bit of a newb to go and I don't know if there is some future error .. or something like the bot does not have the correct discord permissions?
The reason it was not posting was because the bot did not have the Manage Messages permission. This can be done by checking the Manage Messages checkbox when generating the invite link on the OAuth tab.
Related
I am running some loadtesting on a go program that use some channels.
Sending message to channel using below code, available here
.
select {
case globals.hub.join <- msg:
default:
// Reply with a 500 to the user.
s.queueOut(ErrUnknownReply(msg, msg.Timestamp))
s.inflightReqs.Done()
logs.Err.Println("s.subscribe: hub.join queue full, topic ", msg.RcptTo, s.sid)
}
Channel implementation is as below, available here.
select {
case join := <-h.join:
logs.Info.Println("hub.go : hub case join")
...
...
}
In normal scenario, the code is working fine, but when loadtested/load is increased to the server, the channel does not receive mesages sent to it. The channel reaches to a not responsding state. Is there a possible explanation for this?
Any help is appreciated.
Full code of this available here .
im trying to find out a way to get the author of the message that somebody has reacted to.
> e.getChannel().getHistory().getMessageById(e.getMessageId()).getAuthor();
this is what i've got but it returns null
Use GuildMessageReactionAddEvent#retrieveMessage:
event.retrieveMessage().queue(message -> {
... code that uses the message ...
});
I cloned the gorilla websocket chat example and updated it to use multiple rooms. However, I am getting the error:
Error during WebSocket handshake: Unexpected response code: 404
In chrome whenever I try to make the connection. My source code is available on github. It is very similar to the original example, and was only changed slightly. I don't know why it is not working.
EDIT:
The problem is occuring in this line of code:
for _, name := range []string{"arduino", "java", "go", "scala"} {
room := newRoom("go")
http.Handle("/chat/go", room)
go room.run()
}
Looping over a slice is causing an issue with the httphandle function. If instead, I declare them individually:
room := newRoom("go")
http.Handle("/chat/go", room)
go room.run()
...
It works. How can I fix this?
So actually from your index.html file, you connect to wrong url
<!-- index.html -->
<script>
var serviceLocation = "ws://0.0.0.0:8080/chat/";
.....
function connectToChatserver() {
room = $('#chatroom option:selected').val();
wsocket = new WebSocket(serviceLocation + room);
// it connect to /chat/<room>, it has slash after chat
This is your url from main.go
http.Handle("/chat"+name, room)
It will make url like this: http://localhost:8080/chatgo, rather than what you want: http://localhost:8080/chat/go
Fyi, it will error because you don't properly handle the channel, so after I send 1 message, it will be automatically closed. But this is another topic.
2020/08/04 06:42:10 running chat room java
2020/08/04 06:42:10 running chat room go
2020/08/04 06:42:10 running chat room arduino
2020/08/04 06:42:10 running chat room scala
2020/08/04 06:42:15 new client in room arduino
2020/08/04 06:42:15 client leaving room arduino
2020/08/04 06:42:15 client leaving room arduino
panic: close of closed channel
goroutine 6 [running]:
main.(*Room).run(0xc00007ac90)
/home/fahim/Projects/Golang/go-chat/room.go:70 +0x3b5
created by main.main
/home/fahim/Projects/Golang/go-chat/main.go:17 +0x2bd
exit status 2
how do unity check if player manually sign out from the leaderboard in google play service. I am using the GPG plugin for this and my platform is in android
This is a bit dated, but I was just looking into this and thought I'd share what I found.
When you sign out from within the leaderboard (or achievements page), the GPG plugin gives you an error that looks like this:
** [Play Games Plugin DLL] ERROR: Authentication has been lost!
which causes PlayGamesPlatform.Instance.IsAuthenticated () to return false.
One way to find catch this is simply listening to the script that is displaying the message. Their log function is written below. Just look at the msg arg and toggle your variable you are using to keep track of the logged in state.
- GooglePlayGames > OurUtils > Logger.cs
...
public static void e(string msg) {
Debug.LogWarning("*** " + LOG_PREF + " ERROR: " + msg);
if (msg == "Authentication has been lost!") {
// yourScript.isLoggedIn = false;
}
}
...
Alternatively, you could check the value of PlayGamesPlatform.Instance.IsAuthenticated() when the user attempts to access one of the GPG services (leaderboard, achievements, etc). If it is false, the user is not signed in and should be prompted to sign in rather than firing the service.
I learning Hornetq code recently, and have a doubt about JMSbridge.
you can see, there has a fun named "sendMessages()" in the JMSbridgeImpl.java. the fun send msg to the remote JMSServer, but without doing acknowledge.
but int the fun named "sendBatchNonTransacted()" , there just dong acknowledge with the last msg, such as "messages.getLast().acknowledge();"
so the question is: why not do ack by the each msg in the fun named "sendMessages()"?
apologize, my English is pool.
I'm online waiting for you help! thank you !
--------------------------------------------
oh, thanks "Moj Far" very much for the frist question, i got it.
but i have a other question: i modifid the hornetQ source codes,
i want to use ClientConsumer(have successful init) to get msg in the local HornetQ
and use JMS producer to send msg to the remote JMSServer.
In the "Run" function of the "SourceReceiver" class, i modyfy as this:
if (bridgeType == JMSBridgeImpl.ALL_NETTY_MODE ) {
msg = sourceConsumer.receive(1000);
} else { /* core client receive msg */
cmsg = localClientConsumer.receive(1000);
if (cmsg != null) {
hq_msg = HornetQMessage.createMessage(cmsg, localClientSession);
//hq_msg = HornetQMessage.createMessage(cmsg, null);
hq_msg.doBeforeReceive();
//cmsg.acknowledge(); do ack after send
msg = hq_msg;
}
}
but after 2 hours runing, the VM memary is Overflow.
i alsotry to not use localClientSession to create HornetQMessage,but the memory is also Overflow.
is there something wrong in my code?
We have two ways for guarantee of sending messages:
Transactional (used in sendBatchLocalTx() and sendBatchXA())
Non Transactional or Acknowledgement (used in sendBatchNonTransacted())
All of sendBatchLocalTx(), sedBatchXA(), and sendBatchNonTransacted(), use sendMessages() for sending messages, then guarantee sending messages with their own way (commit a transaction or ack messages)!
In sendBatchNonTransacted(), it uses Client Acknowledgement Mode; In this mode, with acking a message (here, the last message), all sent messages in current session will be acked!