Skip to content

Commit

Permalink
improve DiscordMessage error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Aug 6, 2021
1 parent 87046cf commit 289378f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
@@ -1,6 +1,7 @@
package com.denizenscript.ddiscordbot.commands;

import com.denizenscript.ddiscordbot.DenizenDiscordBot;
import com.denizenscript.ddiscordbot.DiscordConnection;
import com.denizenscript.ddiscordbot.objects.*;
import com.denizenscript.denizencore.exceptions.InvalidArgumentsException;
import com.denizenscript.denizencore.objects.Argument;
Expand Down Expand Up @@ -147,12 +148,13 @@ public void execute(ScriptEntry scriptEntry) {
}

Runnable runner = () -> {
JDA client = DenizenDiscordBot.instance.connections.get(id.asString()).client;
if (client == null) {
DiscordConnection connection = DenizenDiscordBot.instance.connections.get(id.asString());
if (connection == null) {
Debug.echoError("Failed to process DiscordMessage command: unknown bot ID!");
scriptEntry.setFinished(true);
return;
}
JDA client = connection.client;
MessageChannel toChannel = null;
if (reply != null && reply.channel_id != 0) {
toChannel = client.getTextChannelById(reply.channel_id);
Expand Down
Expand Up @@ -65,10 +65,8 @@ public boolean matches(ScriptPath path) {
return false;
}
}
if (path.switches.containsKey("message")) {
if (!runGenericSwitchCheck(path, "message", getEvent().getMessage().getContentRaw())) {
return false;
}
if (!runGenericSwitchCheck(path, "message", getEvent().getMessage().getContentRaw())) {
return false;
}
return super.matches(path);
}
Expand Down

0 comments on commit 289378f

Please sign in to comment.