Whenever a user in my discord sends a message, I try to log that message, however it thinks the message length is always zero. The one exception to this is that the bots own messages it detects perfectly fine.
#Override
public void onMessageReceived(#NotNull MessageReceivedEvent event) {
String message = event.getMessage().getContentRaw();
System.out.println(message + " - " + message.length());
if (!event.getAuthor().isBot()) {
event.getMessage().reply("test").queue();
}
}
The output of the above code in the terminal is as follows when I send a message of "hello":
- 0
test - 4
As it can be seen, the contents and length of my "hello" message is not being recognized, but my bots reply of "test" is recognized perfectly fine. I am quite puzzled by this issue and any help would be appreciated.
You are missing the message content intent. This is explained in the troubleshooting guide.
Related
I'm trying to send a message with attachments to a slack chat, using a slack bot. The connections to the api is done via WebSocket, and until now, everything works fine, everything but sending a message with attachments.
Here is the code snippet that sends the message:
public final void replyInteractive(WebSocketSession session, Event event, InteractiveMessage reply) {
try {
reply.setText(encode(reply.getText()));
reply.setType(EventType.MESSAGE.name().toLowerCase());
if (reply.getChannel() == null && event.getChannelId() != null) {
reply.setChannel(event.getChannelId());
}
session.sendMessage(new TextMessage(reply.toJSONString()));
if (logger.isDebugEnabled()) { // For debugging purpose only
logger.debug("Reply (Message): {}", reply.toJSONString());
}
} catch (IOException e) {
logger.error("Error sending event: {}. Exception: {}", event.getText(), e.getMessage());
}
}
And this is the json this code is sending:
{"type":"message","channel":"D4CJ8B337","text":"New book!","attachments":[{"fallback":"Something went wrong","color":"#3AA3E3","title":"Do you want to buy this book?","actions":[{"name":"Buy","value":"Yes","text":"Buy","type":"button"},{"name":"No","value":"No","text":"No","type":"button"}],"attachment_type":"default","callback_id":"Djisda"}]}
But, as I said, only the text field, "New book!", is being picked up and being shown in the chat. The whole message seems to be valid when I tested it using the Slack Message Builder.
I guess that's it, thanks in advance.
I found the problem. The RTM API does not accept attachments in messages.
From the Slack docs (https://api.slack.com/rtm):
The RTM API only supports posting simple messages formatted using our default message formatting mode. It does not support attachments or other message formatting modes.
To send attachments, you need to use the chat.postMessage method https://api.slack.com/methods/chat.postMessage
I've started on making my own Skype app using Java Skype Api from taksan
https://github.com/taksan/skype-java-api
(I prefer Java instead of C# because I don't know C# yet)
But my simple method on sending message doesn't work. I don't know if I'm missing something or they updated skype and therefore this api is outdated.
I tried two methods in Java FX called from a button. Both should send testing message to one of my friends. And yes, I've allowed the program in skype.
private void sendMsg2() throws SkypeException {
Skype.chat("skype_ID").send("Sending test message ...");
}
private void sendMsg(Friend[] friends) throws SkypeException {
for (Friend akt : friends) {
if (akt.getId().equals("friend's skype ID")) {
akt.send("Test message 2");
System.out.println("Sending test message 2...");
}
}
}
Both have same results. Message won't send. Look at the picture: http://imgur.com/dfXyV1t
I'm trying to send message to one person (so it's not chat group). Any suggestions please?
when a user executes a command, I would like to send the output back to only that user, not the channel.
I'm using the PircBotX framework.
My Code:
public void onMessage(MessageEvent<PircBotX> event) {
if (event.getMessage().equalsIgnoreCase("!test")){
event.respond("Test Successful.");
}else if (event.getMessage().split(" ")[1].equalsIgnoreCase("!test2")){
event.getChannel().send().message("this response works");
event.respond("This response works");
event.getUser().send().message("but this does not work");
}
}
According to the documentation, event.getUser().send().message("XYZ"); should be a private message.
The documentation also states bot.sendMessage should be a private message, but that this doesn't work either.
For both of these, the console output looks completely normal.
One thought I have as to the origin of the issue: I'm building this as a Twitch.tv chat bot. It is possible (although their API page does not mention this) that private messages are disabled.
are you trying to send a whisper ?? if so take a look at this https://discuss.dev.twitch.tv/t/sending-whispers-with-my-irc-bot/4346/6 you need to connect to an extra irc server to send whisper/private messages
try event.respondPrivateMessage("response");
See pirocbotx-docs->MessageEvent.respondPrivateMessage(String response)
(When I say "App" I am only talking about Android, I'm not gonna even try to deal with Apple)
So I have a website that I'd like to develop an Android app for. All I need it to do is show the website(it'll change some styling if being accessed from the app), which I can do just fine.
I use Intel XDK, which works great. But the notification options it offers seems to be just mass-notification stuff, not individualized.
All I want to do is be able to tell users when they get a notification from my website(like a message from another user).
I've looked all over the place for hours and hours and can't find anything useful. There are a ton of extremely complicated Java codes and tutorials, but I don't even know Java. I'm solely a web developer and all I want is an app that makes it easier for users to check the website.
I'm hoping there is some Java file out there that I can send data to somehow that will allow me to create and delete push notifications on Android systems. Maybe a HTML5 library or JS function, I dunno.
I simply can't seem to implement it myself, and I'm definitely not going to learn an entire dying language just for one basic thing that should be simple to do. Anything you guys can provide would be greatly appreciated. Optimally I would like to get a Java file I can download and put into my app that gives a notification, then I can edit it to say what I need it to or whatever(I also would really like a way to make the notification go away[in case the user sees it on another device before seeing it on the phone] ). I would also need to know how to call onto this Java file, make it check for notifications on the server or whatever.
I know this is all very nooby stuff, but I run an independent website and simply don't have the time to learn all this stuff when my needs are so basic. Thanks in advance.
You can use appMobi for push messaging, see documentation at http://docs.appmobi.com/index.php/push-messages/pushjsapi/. You can setup your appMobi account in the Services tab of the Intel XDK.
//Check if user is registered
var onDeviceReady=function() {
//See if the push user exists already
//You can send any unique user id and password.
AppMobi.notification.checkPushUser(AppMobi.device.uuid, AppMobi.device.uuid);
};
document.addEventListener("appMobi.device.ready",onDeviceReady,false);
//if user is not registered, register them
var isUserAdded = false;
var notificationsRegistered=function(event) {
if(event.success === false) {
if (!isUserAdded) {
isUserAdded= true;
AppMobi.notification.addPushUser(AppMobi.device.uuid,
AppMobi.device.uuid,
'no#email.com');
return;
}
AppMobi.notification.alert("Notifications Failed: " + event.message,
"My Message","OK");
return;
}
var msg = event.message || 'success';
AppMobi.notification.alert("Notifications Enabled: " + msg,
"My Message","OK");
};
document.addEventListener("appMobi.notification.push.enable",
notificationsRegistered,false);
//when push message event is found get notification
var receivedPush = function(){
var myNotifications=AppMobi.notification.getNotificationList();
//It may contain more than one message, so iterate over them
var len=myNotifications.length;
if(len > 0) {
for(i=0; i < len; i++) {
msgObj=AppMobi.notification.getNotificationData(myNotifications[i]);
try{
if(typeof msgObj == "object" && msgObj.id == myNotifications[i]){
AppMobi.notification.alert(msgObj.msg + "\n" + msgObj.data
+ "\n" + msgObj.userkey,"pushMobi Message","OK");
//Always delete messages after they are shown
AppMobi.notification.deletePushNotifications(msgObj.id);
return;
}
AppMobi.notification.alert("Invalid Message Object: " + i,
"My Message","OK");
}catch(e){
AppMobi.notification.alert("Caught Exception For: " + msgObj.id,
"My Message","OK");
AppMobi.notification.deletePushNotifications(msgObj.id);
}
}
}
};
document.addEventListener("appMobi.notification.push.receive", receivedPush, false);
//send a push notification from your website
AppMobi.notification.sendPushNotification(myAppMobiUserID,"new website blog posted!",{});
document.addEventListener("appMobi.notification.push.send",updateNotificationEvent,false);
var updateNotificationEvent=function(event)
{
if(event.success==false)
{
alert("error: " + event.message)
}
else
{
alert("success");
}
}
You can also use Parse.com APIs but I don't believe the subscribe to channel JavaScript API is fully flushed out last I checked, see https://www.parse.com/docs/push_guide#top/JavaScript.
Parse.initialize("YOUR KEY", "HERE");
// Save the current Installation to Parse.
ParseInstallation.getCurrentInstallation().saveInBackground();
You can then send push notifications through the Web Console, or on your website using:
//The following code will push the alert to the "Winterhawks" and "Oil Kings" channels.
Parse.Push.send({
channels: [ "Winterhawks", "Oil Kings" ],
data: {
alert: "The Winterhawks won against the Oil Kings!"
}
}, {
success: function() {
// Push was successful
},
error: function(error) {
// Handle error
}
});
Subscribe to channels is not yet implemented for JavaScript as far as I know so you'll have to use REST or native APIs.
I have an application which requires sending sms from one user to another.On receiving this sms it sends back a reply sms.I have developed a code but the problem is it goes in aloop of sending again and again from one user to another.For example if user 1 sends some sms to user 2,then a sms is automatically sent to user 1 which in turn automatically sends sms to user 2 again and this goes again and again.How can I avoid that? I have to send the reply sms only once from user 2 to user 1 and then no return sms.Please help me with this code.
Here is my code:
http://pastebin.com/rt2Dd20k
Thanks in advance.
If you know the exact text that the automated SMS reply will contain, can't you just put a condition around the block that sends the reply?
String autoReplyText = "Whats up";
boolean isAutoReply = msgs[i].getMessageBody().toString().equals(autoReplyText);
if (!isAutoReply) {
sms.sendTextMessage(str2, null, autoReplyText, pi, null);
}
edit: if the message is dynamic (which it seems that it needs to be, based on your comments) then you could ensure that all automatic replies start with a special string token which identifies them as an automatic reply. This way, if you receive a message that starts with your token, you know you don't need to reply:
String autoReplyToken = "[BANANA]";
String autoReplyText = autoReplyToken + " dynamic message content";
boolean isAutoReply = msgs[i].getMessageBody().toString().startsWith(autoReplyToken);
if (!isAutoReply) {
sms.sendTextMessage(str2, null, autoReplyText, pi, null);
}