Skip to content

Commit 1aef57e

Browse files
Merge remote-tracking branch 'freya/feature/invite-targets'
# Conflicts: # src/main/java/net/dv8tion/jda/api/entities/Invite.java # src/main/java/net/dv8tion/jda/api/requests/ErrorResponse.java
2 parents 0a27191 + c419d36 commit 1aef57e

14 files changed

Lines changed: 1769 additions & 9 deletions

File tree

2026-01-16-we-need-to-remove-the-bots-token-when-interacting.txt

Lines changed: 347 additions & 0 deletions
Large diffs are not rendered by default.

src/main/java/net/dv8tion/jda/api/entities/Invite.java

Lines changed: 397 additions & 1 deletion
Large diffs are not rendered by default.

src/main/java/net/dv8tion/jda/api/entities/channel/attribute/IInviteContainer.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import net.dv8tion.jda.api.requests.RestAction;
2323
import net.dv8tion.jda.api.requests.restaction.InviteAction;
2424

25+
import java.util.Collection;
2526
import java.util.List;
2627

2728
import javax.annotation.CheckReturnValue;
@@ -38,6 +39,14 @@ public interface IInviteContainer extends GuildChannel {
3839
* new {@link net.dv8tion.jda.api.entities.Invite Invite}.
3940
* <br>Requires {@link net.dv8tion.jda.api.Permission#CREATE_INSTANT_INVITE CREATE_INSTANT_INVITE} in this channel.
4041
*
42+
* <p>Possible {@link net.dv8tion.jda.api.requests.ErrorResponse ErrorResponses} include:
43+
* <ul>
44+
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#MISSING_PERMISSIONS Missing Permissions}
45+
* <br>If the bot does not have the {@link net.dv8tion.jda.api.Permission#CREATE_INSTANT_INVITE CREATE_INSTANT_INVITE} permission in the target guild.</li>
46+
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#INVALID_FORM_BODY Invalid Form Body}
47+
* <br>If at least one {@linkplain InviteAction#setTargetUsers(Collection) target user} ID is invalid.</li>
48+
* </ul>
49+
*
4150
* @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException
4251
* If the account does not have {@link net.dv8tion.jda.api.Permission#CREATE_INSTANT_INVITE CREATE_INSTANT_INVITE} in this channel
4352
* @throws java.lang.IllegalArgumentException

src/main/java/net/dv8tion/jda/api/requests/ErrorResponse.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ public enum ErrorResponse {
8181
UNKNOWN_SCHEDULED_EVENT_USER(10071, "Unknown Scheduled Event User"),
8282
UNKNOWN_TAG(10087, "Unknown Tag"),
8383
UNKNOWN_SOUND(10097, "Unknown sound"),
84+
UNKNOWN_INVITE_TARGET_USERS_JOB(10124, "Unknown Invite Target Users Job (invite exists but has no target users)"),
85+
UNKNOWN_INVITE_TARGET_USERS(10129, "Unknown Invite Target Users (invite exists but has no target users)"),
8486
BOTS_NOT_ALLOWED(20001, "Bots cannot use this endpoint"),
8587
ONLY_BOTS_ALLOWED(20002, "Only bots can use this endpoint"),
8688
EXPLICIT_CONTENT_CANNOT_SEND_TO_RECIPIENT(20009, "Explicit content cannot be sent to the desired recipient(s)"),
@@ -149,6 +151,7 @@ public enum ErrorResponse {
149151
FORUM_POST_TAG_REQUIRED(40067, "A tag is required to create a forum post in this channel"),
150152
DUPLICATE_RESOURCE_ENTITLEMENT(40074, "An entitlement has already been granted for this resource"),
151153
MAX_FOLLOW_UP_MESSAGES_HIT(40094, "This interaction has hit the maximum number of follow up messages"),
154+
INVITE_TARGET_USERS_FILE_NOT_PROCESSED(40115, "Target users file has not been processed"),
152155
CLOUDFLARE_BLOCKED_REQUEST(
153156
40333, "Cloudflare is blocking your request. This can often be resolved by setting a proper User Agent"),
154157
MISSING_ACCESS(50001, "Missing Access"),

src/main/java/net/dv8tion/jda/api/requests/Route.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,11 @@ public static class Invites {
343343
public static final Route GET_CHANNEL_INVITES = new Route(GET, "channels/{channel_id}/invites");
344344
public static final Route CREATE_INVITE = new Route(POST, "channels/{channel_id}/invites");
345345
public static final Route DELETE_INVITE = new Route(DELETE, "invites/{code}");
346+
347+
public static final Route GET_TARGET_USERS = new Route(GET, "invites/{code}/target-users");
348+
public static final Route UPDATE_TARGET_USERS = new Route(PUT, "invites/{code}/target-users");
349+
public static final Route GET_TARGET_USERS_JOB_STATUS =
350+
new Route(GET, "invites/{code}/target-users/job-status");
346351
}
347352

348353
public static class Templates {

src/main/java/net/dv8tion/jda/api/requests/restaction/InviteAction.java

Lines changed: 261 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616

1717
package net.dv8tion.jda.api.requests.restaction;
1818

19-
import net.dv8tion.jda.api.entities.Invite;
20-
import net.dv8tion.jda.api.entities.Member;
21-
import net.dv8tion.jda.api.entities.User;
19+
import net.dv8tion.jda.api.entities.*;
2220
import net.dv8tion.jda.api.utils.MiscUtil;
2321
import net.dv8tion.jda.internal.utils.Checks;
2422

23+
import java.util.Arrays;
24+
import java.util.Collection;
2525
import java.util.concurrent.TimeUnit;
2626
import java.util.function.BooleanSupplier;
2727

@@ -234,4 +234,262 @@ default InviteAction setTargetStream(@Nonnull Member member) {
234234
Checks.notNull(member, "Member");
235235
return setTargetStream(member.getIdLong());
236236
}
237+
238+
/**
239+
* Sets the users allowed to use this invite.
240+
* <br>This requires the {@link net.dv8tion.jda.api.Permission#MANAGE_SERVER MANAGE_SERVER} permission!
241+
*
242+
* <p>If unknown users are found,
243+
* Discord will respond to the request with {@link net.dv8tion.jda.api.requests.ErrorResponse#INVALID_FORM_BODY Invalid Form Body}.
244+
*
245+
* @param users
246+
* The users allowed to use the invite
247+
*
248+
* @throws IllegalArgumentException
249+
* If the provided collection is or contains {@code null}
250+
* @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException
251+
* If the {@linkplain Guild#getSelfMember() self member}
252+
* does not have the {@link net.dv8tion.jda.api.Permission#MANAGE_SERVER MANAGE_SERVER} permission
253+
*
254+
* @return This instance for chaining
255+
*/
256+
@Nonnull
257+
@CheckReturnValue
258+
InviteAction setTargetUsers(@Nonnull Collection<? extends UserSnowflake> users);
259+
260+
/**
261+
* Sets the users allowed to use this invite.
262+
* <br>This requires the {@link net.dv8tion.jda.api.Permission#MANAGE_SERVER MANAGE_SERVER} permission!
263+
*
264+
* <p>If unknown users are found,
265+
* Discord will respond to the request with {@link net.dv8tion.jda.api.requests.ErrorResponse#INVALID_FORM_BODY Invalid Form Body}.
266+
*
267+
* @param users
268+
* The users allowed to use the invite
269+
*
270+
* @throws IllegalArgumentException
271+
* If the provided array is or contains {@code null}
272+
* @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException
273+
* If the {@linkplain Guild#getSelfMember() self member}
274+
* does not have the {@link net.dv8tion.jda.api.Permission#MANAGE_SERVER MANAGE_SERVER} permission
275+
*
276+
* @return This instance for chaining
277+
*/
278+
@Nonnull
279+
@CheckReturnValue
280+
InviteAction setTargetUsers(@Nonnull UserSnowflake... users);
281+
282+
/**
283+
* Sets IDs of users allowed to use this invite.
284+
* <br>This requires the {@link net.dv8tion.jda.api.Permission#MANAGE_SERVER MANAGE_SERVER} permission!
285+
*
286+
* <p>If unknown users are found,
287+
* Discord will respond to the request with {@link net.dv8tion.jda.api.requests.ErrorResponse#INVALID_FORM_BODY Invalid Form Body}.
288+
*
289+
* @param ids
290+
* IDs of users allowed to use the invite
291+
*
292+
* @throws IllegalArgumentException
293+
* If the provided collection is or contains {@code null}
294+
* @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException
295+
* If the {@linkplain Guild#getSelfMember() self member}
296+
* does not have the {@link net.dv8tion.jda.api.Permission#MANAGE_SERVER MANAGE_SERVER} permission
297+
*
298+
* @return This instance for chaining
299+
*/
300+
@Nonnull
301+
@CheckReturnValue
302+
InviteAction setTargetUserIds(@Nonnull Collection<Long> ids);
303+
304+
/**
305+
* Sets IDs of users allowed to use this invite.
306+
* <br>This requires the {@link net.dv8tion.jda.api.Permission#MANAGE_SERVER MANAGE_SERVER} permission!
307+
*
308+
* <p>If unknown users are found,
309+
* Discord will respond to the request with {@link net.dv8tion.jda.api.requests.ErrorResponse#INVALID_FORM_BODY Invalid Form Body}.
310+
*
311+
* @param ids
312+
* IDs of users allowed to use the invite
313+
*
314+
* @throws IllegalArgumentException
315+
* If the provided array is or contains {@code null}
316+
* @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException
317+
* If the {@linkplain Guild#getSelfMember() self member}
318+
* does not have the {@link net.dv8tion.jda.api.Permission#MANAGE_SERVER MANAGE_SERVER} permission
319+
*
320+
* @return This instance for chaining
321+
*/
322+
@Nonnull
323+
@CheckReturnValue
324+
InviteAction setTargetUserIds(@Nonnull long... ids);
325+
326+
/**
327+
* Sets IDs of users allowed to use this invite.
328+
* <br>This requires the {@link net.dv8tion.jda.api.Permission#MANAGE_SERVER MANAGE_SERVER} permission!
329+
*
330+
* <p>If unknown users are found,
331+
* Discord will respond to the request with {@link net.dv8tion.jda.api.requests.ErrorResponse#INVALID_FORM_BODY Invalid Form Body}.
332+
*
333+
* @param ids
334+
* IDs of users allowed to use the invite
335+
*
336+
* @throws IllegalArgumentException
337+
* <ul>
338+
* <li>If the provided array is or contains {@code null}</li>
339+
* <li>If one of the strings is empty</li>
340+
* </ul>
341+
* @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException
342+
* If the {@linkplain Guild#getSelfMember() self member}
343+
* does not have the {@link net.dv8tion.jda.api.Permission#MANAGE_SERVER MANAGE_SERVER} permission
344+
* @throws NumberFormatException
345+
* If one of the IDs is an invalid snowflake
346+
*
347+
* @return This instance for chaining
348+
*/
349+
@Nonnull
350+
@CheckReturnValue
351+
InviteAction setTargetUserIds(@Nonnull String... ids);
352+
353+
/**
354+
* Sets roles to be assigned when accepting the created invite.
355+
* <br>This requires the {@link net.dv8tion.jda.api.Permission#MANAGE_ROLES MANAGE_ROLES} permission!
356+
*
357+
* @param roles
358+
* The roles to assign upon invite acceptation
359+
*
360+
* @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException
361+
* If the {@linkplain Guild#getSelfMember() self member}
362+
* does not have the {@link net.dv8tion.jda.api.Permission#MANAGE_ROLES MANAGE_ROLES} permission
363+
* @throws net.dv8tion.jda.api.exceptions.HierarchyException
364+
* If the {@linkplain Guild#getSelfMember() self member}
365+
* cannot {@linkplain SelfMember#canInteract(Role) interact} with one of the roles
366+
* due to the role being higher than the bot's highest role
367+
* @throws IllegalArgumentException
368+
* <ul>
369+
* <li>If the provided collection is {@code null} or contains {@code null}</li>
370+
* <li>If one of the roles isn't from the target guild</li>
371+
* </ul>
372+
*
373+
* @return The current InviteAction for chaining.
374+
*/
375+
@Nonnull
376+
@CheckReturnValue
377+
InviteAction setRoles(@Nonnull Collection<? extends Role> roles);
378+
379+
/**
380+
* Sets roles to be assigned when accepting the created invite.
381+
* <br>This requires the {@link net.dv8tion.jda.api.Permission#MANAGE_ROLES MANAGE_ROLES} permission!
382+
*
383+
* @param roles
384+
* The roles to assign upon invite acceptation
385+
*
386+
* @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException
387+
* If the {@linkplain Guild#getSelfMember() self member}
388+
* does not have the {@link net.dv8tion.jda.api.Permission#MANAGE_ROLES MANAGE_ROLES} permission
389+
* @throws net.dv8tion.jda.api.exceptions.HierarchyException
390+
* If the {@linkplain Guild#getSelfMember() self member}
391+
* cannot {@linkplain SelfMember#canInteract(Role) interact} with one of the roles
392+
* due to the role being higher than the bot's highest role
393+
* @throws IllegalArgumentException
394+
* <ul>
395+
* <li>If the provided array is {@code null} or contains {@code null}</li>
396+
* <li>If one of the roles isn't from the target guild</li>
397+
* </ul>
398+
*
399+
* @return The current InviteAction for chaining.
400+
*/
401+
@Nonnull
402+
@CheckReturnValue
403+
default InviteAction setRoles(@Nonnull Role... roles) {
404+
Checks.noneNull(roles, "Roles");
405+
return setRoles(Arrays.asList(roles));
406+
}
407+
408+
/**
409+
* Sets IDs of roles to be assigned when accepting the created invite.
410+
* <br>This requires the {@link net.dv8tion.jda.api.Permission#MANAGE_ROLES MANAGE_ROLES} permission!
411+
*
412+
* <p>IDs that do not point to an existing role in the targeted guild will be ignored.
413+
*
414+
* @param ids
415+
* The IDs of the roles to assign upon invite acceptation
416+
*
417+
* @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException
418+
* If the {@linkplain Guild#getSelfMember() self member}
419+
* does not have the {@link net.dv8tion.jda.api.Permission#MANAGE_ROLES MANAGE_ROLES} permission
420+
* @throws net.dv8tion.jda.api.exceptions.HierarchyException
421+
* If the {@linkplain Guild#getSelfMember() self member}
422+
* cannot {@linkplain SelfMember#canInteract(Role) interact} with one of the roles
423+
* due to the role being higher than the bot's highest role
424+
* @throws IllegalArgumentException
425+
* If the provided collection is {@code null} or contains {@code null}
426+
*
427+
* @return The current InviteAction for chaining.
428+
*/
429+
@Nonnull
430+
@CheckReturnValue
431+
default InviteAction setRoleIds(@Nonnull Collection<Long> ids) {
432+
Checks.noneNull(ids, "IDs");
433+
return setRoleIds(ids.stream().mapToLong(Long::longValue).toArray());
434+
}
435+
436+
/**
437+
* Sets IDs of roles to be assigned when accepting the created invite.
438+
* <br>This requires the {@link net.dv8tion.jda.api.Permission#MANAGE_ROLES MANAGE_ROLES} permission!
439+
*
440+
* <p>IDs that do not point to an existing role in the targeted guild will be ignored.
441+
*
442+
* @param ids
443+
* The IDs of the roles to assign upon invite acceptation
444+
*
445+
* @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException
446+
* If the {@linkplain Guild#getSelfMember() self member}
447+
* does not have the {@link net.dv8tion.jda.api.Permission#MANAGE_ROLES MANAGE_ROLES} permission
448+
* @throws net.dv8tion.jda.api.exceptions.HierarchyException
449+
* If the {@linkplain Guild#getSelfMember() self member}
450+
* cannot {@linkplain SelfMember#canInteract(Role) interact} with one of the roles
451+
* due to the role being higher than the bot's highest role
452+
* @throws IllegalArgumentException
453+
* If the provided array is {@code null}
454+
*
455+
* @return The current InviteAction for chaining.
456+
*/
457+
@Nonnull
458+
@CheckReturnValue
459+
InviteAction setRoleIds(@Nonnull long... ids);
460+
461+
/**
462+
* Sets IDs of roles to be assigned when accepting the created invite.
463+
* <br>This requires the {@link net.dv8tion.jda.api.Permission#MANAGE_ROLES MANAGE_ROLES} permission!
464+
*
465+
* <p>IDs that do not point to an existing role in the targeted guild will be ignored.
466+
*
467+
* @param ids
468+
* The IDs of the roles to assign upon invite acceptation
469+
*
470+
* @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException
471+
* If the {@linkplain Guild#getSelfMember() self member}
472+
* does not have the {@link net.dv8tion.jda.api.Permission#MANAGE_ROLES MANAGE_ROLES} permission
473+
* @throws net.dv8tion.jda.api.exceptions.HierarchyException
474+
* If the {@linkplain Guild#getSelfMember() self member}
475+
* cannot {@linkplain SelfMember#canInteract(Role) interact} with one of the roles
476+
* due to the role being higher than the bot's highest role
477+
* @throws IllegalArgumentException
478+
* If the provided array is {@code null}, contains {@code null}, or, has an empty string
479+
* @throws NumberFormatException
480+
* If one of the IDs is not a valid snowflake
481+
*
482+
* @return The current InviteAction for chaining.
483+
*/
484+
@Nonnull
485+
@CheckReturnValue
486+
default InviteAction setRoleIds(@Nonnull String... ids) {
487+
Checks.noneNull(ids, "IDs");
488+
489+
long[] arr = new long[ids.length];
490+
for (int i = 0; i < ids.length; i++) {
491+
arr[i] = MiscUtil.parseSnowflake(ids[i]);
492+
}
493+
return setRoleIds(arr);
494+
}
237495
}

0 commit comments

Comments
 (0)