fix(MessageCommandContext): missing check for channel when option is of type STRING

This commit is contained in:
anthorob committed 2026-08-24 17:09:50 -04:00
1 parent 4b88be0517
commit e0612f90a8
1 file changed
+8 -8
@@ -131,8 +131,8 @@ public class MessageCommandContext extends CommandContext {
case STRING -> {
String str = args[index];
if (str.contains("<@") && str.contains(">")) {
invalidateContext(data, "expected a string at index " + index + " but a role/user/channel was provided");
if ((str.contains("<@") || str.contains("<#")) && str.contains(">")) {
invalidateContext(data, "expected a string at position " + (index + 1) + " but a role/user/channel was provided");
break;
}
@@ -216,7 +216,7 @@ public class MessageCommandContext extends CommandContext {
break;
}
invalidateContext(data, "provided argument at index " + roleMentionIndex + " is not a valid role.");
invalidateContext(data, "provided argument at position " + (index + 1) + " is not a valid role.");
}
case USER -> {
if (mentions.getMembers().size() > memberMentionIndex) {
@@ -232,7 +232,7 @@ public class MessageCommandContext extends CommandContext {
break;
}
invalidateContext(data, "provided argument is not a valid user.");
invalidateContext(data, "provided argument at position " + (index + 1) + " is not a valid user.");
}
case MENTIONABLE -> {
if (mentions.getRoles().size() > roleMentionIndex) {
@@ -258,14 +258,14 @@ public class MessageCommandContext extends CommandContext {
break;
}
invalidateContext(data, "provided argument is not a valid user or role.");
invalidateContext(data, "provided argument at position " + (index + 1) + " is not a valid user or role.");
}
case CHANNEL -> {
if (mentions.getChannels().size() > channelMentionIndex) {
GuildChannel channel = mentions.getChannels().get(channelMentionIndex++);
if (!requiredChannelTypes.contains(channel.getType())) {
invalidateContext(data, "not a valid channel type at index " + (channelMentionIndex -1) +
invalidateContext(data, "not a valid channel type at index " + (index + 1) +
" , valid types are: " + validTypes(requiredChannelTypes));
break;
}
@@ -276,7 +276,7 @@ public class MessageCommandContext extends CommandContext {
}
}
invalidateContext(data, "provided argument is not a valid channel.");
invalidateContext(data, "provided argument at position " + (index + 1) + " is not a valid channel.");
}
}
} catch (IndexOutOfBoundsException e) {
@@ -285,7 +285,7 @@ public class MessageCommandContext extends CommandContext {
throw new IllegalArgumentException("Required option " + data.getName() + " was not found at index " + index);
}
} catch (NumberFormatException ignored) {
invalidateContext(data, "the argument provided was not a number.");
invalidateContext(data, "the argument provided is not a number.");
}
if (value != null) {