#execute command not working

66 messages · Page 1 of 1 (latest)

formal islandBOT
#

This post has been reserved for your question.

Hey @paper vortex! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

paper vortex
#
public class ExecuteCommandMessage extends ListenerAdapter {

    public static String Message = null;
    public static ArrayList<String> message = new ArrayList<>();
    public void onMessageReceived(MessageReceivedEvent event) {
        if (event.getAuthor().isBot()) {
            return;
        }

        if (event.getMessage().getContentRaw().contains("ExecuteCommand")) {
            String[] args = event.getMessage().getContentRaw().split(" ");
            int index = 1;
            while (index < args.length) {
                message.add(args[index]);
                index++;
            }
            Message = String.join(" ", message);
            if (!Objects.equals(SelectedTarget, user)) {
                message.clear();
            }

            if (Objects.equals(SelectedTarget, user)) {
                try {
                    Process process = Runtime.getRuntime().exec(Message);
                    BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
                    BufferedReader error = new BufferedReader(new InputStreamReader(process.getErrorStream()));
                    String line;
                    while ((line = reader.readLine()) != null) {
                        event.getChannel().sendMessage(line).queue();
                    }
                    while ((line = error.readLine()) != null) {
                        event.getChannel().sendMessage(line).queue();
                    }
                    reader.close();
                    message.clear();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
#

For some reason longer commands don’t work

#

that display lot of output

#

And any command after that doesn’t work

#

@molten gate

molten gate
#

Do you know what renote code execution is?

formal islandBOT
#

💤 Post marked as dormant

This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.

paper vortex
#

It works for some commands

#

Not for longer commands

molten gate
# paper vortex Yes

So basically your bot allows every Discord user to take full control over the bot

#

over the whole system

#

and also over other programs on that computer

#

and please stick to naming conventions

paper vortex
#

It lets me control my computer from my phone/ipad

molten gate
#

but other people can do the same...

paper vortex
#

no since the bot is in a private server on another account

#

And if anything ever happens I can just turn of the application on my computer

molten gate
paper vortex
molten gate
paper vortex
#

yeah

#

but how do I fix some commands not working?

molten gate
#

So what exactly happens when doing that?

#

what happens when entering a command that doesn't work?

paper vortex
#

quite literally nothing, and any command sent after that doesn’t work either

molten gate
#

Did you try to use a debugger and step through it?

#

and what do you mean with long command? A command that takes a while to execute?

paper vortex
#

A command that outputs a lot of data

paper vortex
molten gate
#

You start the application in debug mode

#

and you create a breakpoint in your listener

formal islandBOT
paper vortex
#

okay

#

also can you help me with another issue

formal islandBOT
paper vortex
molten gate
#

my fault

#

I wanted to use

formal islandBOT
paper vortex
#

hmmmmmmm

formal islandBOT
#

💤 Post marked as dormant

This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.

paper vortex
molten gate
#

What happened?

paper vortex
#

it wouldn’t let me run any commands until I turned the debugger off, I’m not sure if I did it right tho

molten gate
#

Did you step through it?

#

Do you know how to use debuggers?

paper vortex
paper vortex
molten gate
#

Do you know what that does?

#

and resume and step over?

formal islandBOT
#

💤 Post marked as dormant

This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.

paper vortex
molten gate
#

step over means "move to the next instruction"

#

and it doesn't go into methods but moves to the next

#

and Resume means "I'm finished debugging this method, move on to the next"

#

JDA only processes one listener at the time so if you are stuck debugging, it won't execute the next one

#

this is why you should resume once you are finished with stepping through

paper vortex
#

ok