Exemplo n.º 1
0
  @Override
  public void deleteMessagesByIds(Collection<String> messageIds) {
    if (messageIds.size() < 2 || messageIds.size() > 100) {
      throw new IllegalArgumentException(
          "Must provide at least 2 or at most 100 messages to be deleted.");
    } else if (!PermissionUtil.checkPermission(
        getJDA().getSelfInfo(), Permission.MESSAGE_MANAGE, this)) {
      throw new PermissionException(
          Permission.MESSAGE_MANAGE,
          "Must have MESSAGE_MANAGE in order to bulk delete messages in this channel regardless of author.");
    }

    JSONObject body = new JSONObject().put("messages", messageIds);
    Requester.Response response =
        ((JDAImpl) getJDA())
            .getRequester()
            .post(Requester.DISCORD_API_PREFIX + "channels/" + id + "/messages/bulk_delete", body);
    if (response.isRateLimit())
      throw new RateLimitedException(response.getObject().getInt("retry_after"));
  }
Exemplo n.º 2
0
 @Override
 public void deleteMessages(Collection<Message> messages) {
   deleteMessagesByIds(messages.stream().map(msg -> msg.getId()).collect(Collectors.toList()));
 }