本文整理汇总了Java中net.dv8tion.jda.core.requests.restaction.AuditableRestAction.EmptyRestAction方法的典型用法代码示例。如果您正苦于以下问题:Java AuditableRestAction.EmptyRestAction方法的具体用法?Java AuditableRestAction.EmptyRestAction怎么用?Java AuditableRestAction.EmptyRestAction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.dv8tion.jda.core.requests.restaction.AuditableRestAction
的用法示例。
在下文中一共展示了AuditableRestAction.EmptyRestAction方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: update
import net.dv8tion.jda.core.requests.restaction.AuditableRestAction; //导入方法依赖的package包/类
/**
* Creates a new {@link net.dv8tion.jda.core.requests.RestAction RestAction} instance
* that will apply <b>all</b> changes that have been made to this manager instance.
* <br>If no changes have been made this will simply return {@link net.dv8tion.jda.core.requests.RestAction.EmptyRestAction EmptyRestAction}.
*
* <p>Before applying new changes it is recommended to call {@link #reset()} to reset previous changes.
* <br>This is automatically called if this method returns successfully.
*
* <p>Possible {@link net.dv8tion.jda.core.requests.ErrorResponse ErrorResponses} for this
* update include the following:
* <ul>
* <li>{@link net.dv8tion.jda.core.requests.ErrorResponse#UNKNOWN_EMOJI UNKNOWN_EMOJI}
* <br>If the target Emote was deleted before finishing the task</li>
*
* <li>{@link net.dv8tion.jda.core.requests.ErrorResponse#MISSING_ACCESS MISSING_ACCESS}
* <br>If the currently logged in account was removed from the Guild before finishing the task</li>
*
* <li>{@link net.dv8tion.jda.core.requests.ErrorResponse#MISSING_PERMISSIONS MISSING_PERMISSIONS}
* <br>If the currently logged in account loses the {@link net.dv8tion.jda.core.Permission#MANAGE_EMOTES MANAGE_EMOTES Permission}
* before finishing the task</li>
* </ul>
*
* @throws net.dv8tion.jda.core.exceptions.InsufficientPermissionException
* If the currently logged in account does not have the Permission {@link net.dv8tion.jda.core.Permission#MANAGE_EMOTES MANAGE_EMOTES}
* in the underlying {@link net.dv8tion.jda.core.entities.Guild Guild}.
*
* @return {@link net.dv8tion.jda.core.requests.restaction.AuditableRestAction AuditableRestAction}
* <br>Applies all changes that have been made in a single api-call.
*/
@CheckReturnValue
public AuditableRestAction<Void> update()
{
checkPermission(Permission.MANAGE_EMOTES);
if (!needsUpdate())
return new AuditableRestAction.EmptyRestAction<>(getJDA(), null);
JSONObject body = new JSONObject();
if (name.shouldUpdate())
body.put("name", name.getValue());
if (roles.shouldUpdate())
body.put("roles", roles.getValue().stream().map(ISnowflake::getId).collect(Collectors.toList()));
reset(); //reset because we built the JSONObject needed to update
Route.CompiledRoute route = Route.Emotes.MODIFY_EMOTE.compile(getGuild().getId(), emote.getId());
return new AuditableRestAction<Void>(getJDA(), route, body)
{
@Override
protected void handleResponse(Response response, Request<Void> request)
{
if (response.isOk())
request.onSuccess(null);
else
request.onFailure(response);
}
};
}
示例2: update
import net.dv8tion.jda.core.requests.restaction.AuditableRestAction; //导入方法依赖的package包/类
/**
* Creates a new {@link net.dv8tion.jda.core.requests.RestAction RestAction} instance
* that will apply <b>all</b> changes that have been made to this manager instance.
* <br>If no changes have been made this will simply return {@link net.dv8tion.jda.core.requests.RestAction.EmptyRestAction EmptyRestAction}.
*
* <p>Before applying new changes it is recommended to call {@link #reset()} to reset previous changes.
* <br>This is automatically called if this method returns successfully.
*
* <p>Possible {@link net.dv8tion.jda.core.requests.ErrorResponse ErrorResponses} for this
* update include the following:
* <ul>
* <li>{@link net.dv8tion.jda.core.requests.ErrorResponse#UNKNOWN_ROLE UNKNOWN_ROLE}
* <br>If the Role was deleted before finishing the task</li>
*
* <li>{@link net.dv8tion.jda.core.requests.ErrorResponse#MISSING_ACCESS MISSING_ACCESS}
* <br>If the currently logged in account was removed from the Guild before finishing the task</li>
*
* <li>{@link net.dv8tion.jda.core.requests.ErrorResponse#MISSING_PERMISSIONS MISSING_PERMISSIONS}
* <br>If the currently logged in account loses the {@link net.dv8tion.jda.core.Permission#MANAGE_ROLES MANAGE_ROLES Permission} or lost
* positional power before finishing the task</li>
* </ul>
*
* @throws net.dv8tion.jda.core.exceptions.InsufficientPermissionException
* If the currently logged in account does not have the Permission {@link net.dv8tion.jda.core.Permission#MANAGE_ROLES MANAGE_ROLES}
* @throws net.dv8tion.jda.core.exceptions.HierarchyException
* If the currently logged in account does not meet the required hierarchy position
* to {@link Role#canInteract(net.dv8tion.jda.core.entities.Role) interact} with this Role
*
* @return {@link net.dv8tion.jda.core.requests.restaction.AuditableRestAction AuditableRestAction}
* <br>Applies all changes that have been made in a single api-call.
*/
@CheckReturnValue
public AuditableRestAction<Void> update()
{
checkPermission(Permission.MANAGE_ROLES);
checkPosition();
if (!needsUpdate())
return new AuditableRestAction.EmptyRestAction<>(getJDA(), null);
//TODO: check if all of this is *actually* needed.
JSONObject body = new JSONObject().put("name", role.getName());
if(name.shouldUpdate())
body.put("name", name.getValue());
if(color.shouldUpdate())
body.put("color", color.getValue() == null ? 0 : color.getValue().getRGB() & 0xFFFFFF);
if(hoisted.shouldUpdate())
body.put("hoist", hoisted.getValue().booleanValue());
if(mentionable.shouldUpdate())
body.put("mentionable", mentionable.getValue().booleanValue());
if (permissions.shouldUpdate())
body.put("permissions", permissions.getValue());
reset();
Route.CompiledRoute route = Route.Roles.MODIFY_ROLE.compile(getGuild().getId(), role.getId());
return new AuditableRestAction<Void>(getJDA(), route, body)
{
@Override
protected void handleResponse(Response response, Request<Void> request)
{
if (response.isOk())
request.onSuccess(null);
else
request.onFailure(response);
}
};
}
示例3: update
import net.dv8tion.jda.core.requests.restaction.AuditableRestAction; //导入方法依赖的package包/类
/**
* Creates a new {@link net.dv8tion.jda.core.requests.RestAction RestAction} instance
* that will apply <b>all</b> changes that have been made to this manager instance.
* <br>If no changes have been made this will simply return {@link net.dv8tion.jda.core.requests.RestAction.EmptyRestAction EmptyRestAction}.
*
* <p>Before applying new changes it is recommended to call {@link #reset()} to reset previous changes.
* <br>This is automatically called if this method returns successfully.
*
* <p>Possible {@link net.dv8tion.jda.core.requests.ErrorResponse ErrorResponses} for this
* update include the following:
* <ul>
* <li>{@link net.dv8tion.jda.core.requests.ErrorResponse#UNKNOWN_CHANNEL UNKNOWN_CHANNEL}
* <br>If the TextChannel was deleted before finishing the task</li>
*
* <li>{@link net.dv8tion.jda.core.requests.ErrorResponse#MISSING_ACCESS MISSING_ACCESS}
* <br>If the currently logged in account was removed from the Guild before finishing the task</li>
*
* <li>{@link net.dv8tion.jda.core.requests.ErrorResponse#MISSING_PERMISSIONS MISSING_PERMISSIONS}
* <br>If the currently logged in account loses the {@link net.dv8tion.jda.core.Permission#MANAGE_WEBHOOKS MANAGE_WEBHOOKS Permission}</li>
* </ul>
*
* @throws net.dv8tion.jda.core.exceptions.InsufficientPermissionException
* If the currently logged in account does not have the Permission {@link net.dv8tion.jda.core.Permission#MANAGE_WEBHOOKS MANAGE_WEBHOOKS}
* in either the current or selected new TextChannel.
*
* @return {@link net.dv8tion.jda.core.requests.restaction.AuditableRestAction AuditableRestAction}
* <br>Applies all changes that have been made in a single api-call.
*/
@CheckReturnValue
public AuditableRestAction<Void> update()
{
Member self = getGuild().getSelfMember();
if (!self.hasPermission(webhook.getChannel(), Permission.MANAGE_WEBHOOKS))
throw new InsufficientPermissionException(Permission.MANAGE_WEBHOOKS);
if (channel.isSet() && !self.hasPermission(channel.getValue(), Permission.MANAGE_WEBHOOKS))
throw new InsufficientPermissionException(Permission.MANAGE_WEBHOOKS, "Permission not available in selected new channel");
if (!shouldUpdate())
return new AuditableRestAction.EmptyRestAction<>(getJDA(), null);
JSONObject data = new JSONObject();
data.put("name", name.getOriginalValue());
if (channel.shouldUpdate())
data.put("channel_id", channel.getValue().getId());
if (name.shouldUpdate())
data.put("name", name.getValue());
if (avatar.shouldUpdate())
{
Icon value = avatar.getValue();
data.put("avatar", value != null ? value.getEncoding() : JSONObject.NULL);
}
Route.CompiledRoute route = Route.Webhooks.MODIFY_WEBHOOK.compile(webhook.getId());
return new AuditableRestAction<Void>(getJDA(), route, data)
{
@Override
protected void handleResponse(Response response, Request<Void> request)
{
if (response.isOk())
request.onSuccess(null);
else
request.onFailure(response);
}
};
}
示例4: update
import net.dv8tion.jda.core.requests.restaction.AuditableRestAction; //导入方法依赖的package包/类
/**
* Creates a new {@link net.dv8tion.jda.core.requests.RestAction RestAction} instance
* that will apply <b>all</b> changes that have been made to this manager instance.
* <br>If no changes have been made this will simply return {@link net.dv8tion.jda.core.requests.RestAction.EmptyRestAction EmptyRestAction}.
*
* <p>Before applying new changes it is recommended to call {@link #reset()} to reset previous changes.
* <br>This is automatically called if this method returns successfully.
*
* <p>Possible {@link net.dv8tion.jda.core.requests.ErrorResponse ErrorResponses} for this
* update include the following:
* <ul>
* <li>{@link net.dv8tion.jda.core.requests.ErrorResponse#UNKNOWN_OVERRIDE UNKNOWN_OVERRIDE}
* <br>If the PermissionOverride was deleted before finishing the task</li>
*
* <li>{@link net.dv8tion.jda.core.requests.ErrorResponse#MISSING_ACCESS MISSING_ACCESS}
* <br>If the currently logged in account was removed from the Guild before finishing the task</li>
*
* <li>{@link net.dv8tion.jda.core.requests.ErrorResponse#MISSING_PERMISSIONS MISSING_PERMISSIONS}
* <br>If the currently logged in account loses the {@link net.dv8tion.jda.core.Permission#MANAGE_PERMISSIONS MANAGE_PERMISSIONS Permission}</li>
* </ul>
*
* @throws net.dv8tion.jda.core.exceptions.InsufficientPermissionException
* If the currently logged in account does not have the Permission {@link net.dv8tion.jda.core.Permission#MANAGE_PERMISSIONS MANAGE_PERMISSIONS}
* in the {@link #getChannel() Channel}
*
* @return {@link net.dv8tion.jda.core.requests.restaction.AuditableRestAction AuditableRestAction}
* <br>Applies all changes that have been made in a single api-call.
*/
@CheckReturnValue
public AuditableRestAction<Void> update()
{
checkPermission(Permission.MANAGE_PERMISSIONS);
if (!shouldUpdate())
return new AuditableRestAction.EmptyRestAction<>(getJDA(), null);
String targetId = override.isRoleOverride() ? override.getRole().getId() : override.getMember().getUser().getId();
JSONObject body = new JSONObject()
.put("id", targetId)
.put("type", override.isRoleOverride() ? "role" : "member")
.put("allow", getAllowBits())
.put("deny", getDenyBits());
reset();
Route.CompiledRoute route = Route.Channels.MODIFY_PERM_OVERRIDE.compile(override.getChannel().getId(), targetId);
return new AuditableRestAction<Void>(getJDA(), route, body)
{
@Override
protected void handleResponse(Response response, Request<Void> request)
{
if (response.isOk())
request.onSuccess(null);
else
request.onFailure(response);
}
};
}
示例5: update
import net.dv8tion.jda.core.requests.restaction.AuditableRestAction; //导入方法依赖的package包/类
/**
* Creates a new {@link net.dv8tion.jda.core.requests.RestAction RestAction} instance
* that will apply <b>all</b> changes that have been made to this manager instance.
* <br>If no changes have been made this will simply return {@link net.dv8tion.jda.core.requests.RestAction.EmptyRestAction EmptyRestAction}.
*
* <p>Before applying new changes it is recommended to call {@link #reset()} to reset previous changes.
* <br>This is automatically called if this method returns successfully.
*
* <p>Possible {@link net.dv8tion.jda.core.requests.ErrorResponse ErrorResponses} for this
* update include the following:
* <ul>
* <li>{@link net.dv8tion.jda.core.requests.ErrorResponse#UNKNOWN_CHANNEL UNKNOWN_CHANNEL}
* <br>If the Channel was deleted before finishing the task</li>
*
* <li>{@link net.dv8tion.jda.core.requests.ErrorResponse#MISSING_ACCESS MISSING_ACCESS}
* <br>If the currently logged in account was removed from the Guild before finishing the task</li>
*
* <li>{@link net.dv8tion.jda.core.requests.ErrorResponse#MISSING_PERMISSIONS MISSING_PERMISSIONS}
* <br>If the currently logged in account loses the {@link net.dv8tion.jda.core.Permission#MANAGE_CHANNEL MANAGE_CHANNEL Permission}
* before finishing the task</li>
* </ul>
*
* @throws net.dv8tion.jda.core.exceptions.InsufficientPermissionException
* If the currently logged in account does not have the Permission {@link net.dv8tion.jda.core.Permission#MANAGE_CHANNEL MANAGE_CHANNEL}
* in the underlying {@link net.dv8tion.jda.core.entities.Channel Channel}.
*
* @return {@link net.dv8tion.jda.core.requests.restaction.AuditableRestAction AuditableRestAction}
* <br>Applies all changes that have been made in a single api-call.
*/
@CheckReturnValue
public AuditableRestAction<Void> update()
{
checkPermission(Permission.MANAGE_CHANNEL);
if (!needToUpdate())
return new AuditableRestAction.EmptyRestAction<>(getJDA(), null);
JSONObject frame = new JSONObject().put("name", channel.getName());
if (name.shouldUpdate())
frame.put("name", name.getValue());
if (position.shouldUpdate())
frame.put("position", position.getValue());
if (topic != null && topic.shouldUpdate())
frame.put("topic", topic.getValue() == null ? JSONObject.NULL : topic.getValue());
if (nsfw != null && nsfw.shouldUpdate())
frame.put("nsfw", nsfw.getValue());
if (userLimit != null && userLimit.shouldUpdate())
frame.put("user_limit", userLimit.getValue());
if (bitrate != null && bitrate.shouldUpdate())
frame.put("bitrate", bitrate.getValue());
if (parent != null && parent.shouldUpdate())
frame.put("parent_id", parent.getValue() == null ? JSONObject.NULL : parent.getValue().getIdLong());
reset(); //now that we've built our JSON object, reset the manager back to the non-modified state
Route.CompiledRoute route = Route.Channels.MODIFY_CHANNEL.compile(channel.getId());
return new AuditableRestAction<Void>(channel.getJDA(), route, frame)
{
@Override
protected void handleResponse(Response response, Request<Void> request)
{
if (response.isOk())
request.onSuccess(null);
else
request.onFailure(response);
}
};
}
示例6: update
import net.dv8tion.jda.core.requests.restaction.AuditableRestAction; //导入方法依赖的package包/类
/**
* Creates a new {@link net.dv8tion.jda.core.requests.RestAction RestAction} instance
* that will apply <b>all</b> changes that have been made to this manager instance.
* <br>If no changes have been made this will simply return {@link net.dv8tion.jda.core.requests.RestAction.EmptyRestAction EmptyRestAction}.
*
* <p>Before applying new changes it is recommended to call {@link #reset()} to reset previous changes.
* <br>This is automatically called if this method returns successfully.
*
* <p>Possible {@link net.dv8tion.jda.core.requests.ErrorResponse ErrorResponses} for this
* update include the following:
* <ul>
* <li>{@link net.dv8tion.jda.core.requests.ErrorResponse#UNKNOWN_GUILD UNKNOWN_GUILD}
* <br>If the Guild was deleted before finishing the task</li>
*
* <li>{@link net.dv8tion.jda.core.requests.ErrorResponse#MISSING_PERMISSIONS MISSING_PERMISSIONS}
* <br>If the currently logged in account loses the {@link net.dv8tion.jda.core.Permission#MANAGE_SERVER MANAGE_SERVER Permission}
* before finishing the task</li>
* </ul>
*
* @throws net.dv8tion.jda.core.exceptions.InsufficientPermissionException
* If the currently logged in account does not have the Permission {@link net.dv8tion.jda.core.Permission#MANAGE_SERVER MANAGE_SERVER}
* in the underlying {@link net.dv8tion.jda.core.entities.Guild Guild}
* @throws net.dv8tion.jda.core.exceptions.GuildUnavailableException
* If the Guild is temporarily not {@link net.dv8tion.jda.core.entities.Guild#isAvailable() available}
*
* @return {@link net.dv8tion.jda.core.requests.restaction.AuditableRestAction AuditableRestAction}
* <br>Applies all changes that have been made in a single api-call.
*/
@CheckReturnValue
public AuditableRestAction<Void> update()
{
checkAvailable();
checkPermission(Permission.MANAGE_SERVER);
if (!needToUpdate())
return new AuditableRestAction.EmptyRestAction<>(getJDA(), null);
JSONObject body = new JSONObject().put("name", guild.getName());
if (name.shouldUpdate())
body.put("name", name.getValue());
if (region.shouldUpdate())
body.put("region", region.getValue().getKey());
if (timeout.shouldUpdate())
body.put("afk_timeout", timeout.getValue().getSeconds());
if (icon.shouldUpdate())
body.put("icon", icon.getValue() == null ? JSONObject.NULL : icon.getValue().getEncoding());
if (splash.shouldUpdate())
body.put("splash", splash.getValue() == null ? JSONObject.NULL : splash.getValue().getEncoding());
if (afkChannel.shouldUpdate())
body.put("afk_channel_id", afkChannel.getValue() == null ? JSONObject.NULL : afkChannel.getValue().getId());
if (systemChannel.shouldUpdate())
body.put("system_channel_id", systemChannel.getValue() == null ? JSONObject.NULL : systemChannel.getValue().getId());
if (verificationLevel.shouldUpdate())
body.put("verification_level", verificationLevel.getValue().getKey());
if (defaultNotificationLevel.shouldUpdate())
body.put("default_notification_level", defaultNotificationLevel.getValue().getKey());
if (mfaLevel.shouldUpdate())
body.put("mfa_level", mfaLevel.getValue().getKey());
if (explicitContentLevel.shouldUpdate())
body.put("explicit_content_filter", explicitContentLevel.getValue().getKey());
reset(); //now that we've built our JSON object, reset the manager back to the non-modified state
Route.CompiledRoute route = Route.Guilds.MODIFY_GUILD.compile(guild.getId());
return new AuditableRestAction<Void>(guild.getJDA(), route, body)
{
@Override
protected void handleResponse(Response response, Request<Void> request)
{
if (response.isOk())
request.onSuccess(null);
else
request.onFailure(response);
}
};
}
示例7: setDeafen
import net.dv8tion.jda.core.requests.restaction.AuditableRestAction; //导入方法依赖的package包/类
/**
* Sets the Guild Deafened state state of the {@link net.dv8tion.jda.core.entities.Member Member} based on the provided
* boolean.
*
* <p><b>Note:</b> The Member's {@link net.dv8tion.jda.core.entities.GuildVoiceState#isGuildDeafened() GuildVoiceState.isGuildDeafened()} value won't change
* until JDA receives the {@link net.dv8tion.jda.core.events.guild.voice.GuildVoiceGuildDeafenEvent GuildVoiceGuildDeafenEvent} event related to this change.
*
* <p>Possible {@link net.dv8tion.jda.core.requests.ErrorResponse ErrorResponses} caused by
* the returned {@link net.dv8tion.jda.core.requests.RestAction RestAction} include the following:
* <ul>
* <li>{@link net.dv8tion.jda.core.requests.ErrorResponse#MISSING_PERMISSIONS MISSING_PERMISSIONS}
* <br>The target Member cannot be deafened due to a permission discrepancy</li>
*
* <li>{@link net.dv8tion.jda.core.requests.ErrorResponse#MISSING_ACCESS MISSING_ACCESS}
* <br>We were removed from the Guild before finishing the task</li>
*
* <li>{@link net.dv8tion.jda.core.requests.ErrorResponse#UNKNOWN_MEMBER UNKNOWN_MEMBER}
* <br>The specified Member was removed from the Guild before finishing the task</li>
* </ul>
*
* @param member
* The {@link net.dv8tion.jda.core.entities.Member Member} who's {@link GuildVoiceState VoiceState} is being changed.
* @param deafen
* Whether this {@link net.dv8tion.jda.core.entities.Member Member} should be deafened or undeafened.
*
* @throws net.dv8tion.jda.core.exceptions.InsufficientPermissionException
* If the logged in account does not have the {@link net.dv8tion.jda.core.Permission#VOICE_DEAF_OTHERS} permission.
* @throws net.dv8tion.jda.core.exceptions.HierarchyException
* If the provided member is the Guild's owner. You cannot modify the owner of a Guild.
* @throws IllegalArgumentException
* If the provided member is not from this Guild or null.
* @throws net.dv8tion.jda.core.exceptions.GuildUnavailableException
* If the guild is temporarily not {@link net.dv8tion.jda.core.entities.Guild#isAvailable() available}
*
* @return {@link net.dv8tion.jda.core.requests.restaction.AuditableRestAction AuditableRestAction}
*/
@CheckReturnValue
public AuditableRestAction<Void> setDeafen(Member member, boolean deafen)
{
checkAvailable();
Checks.notNull(member, "Member");
checkGuild(member.getGuild(), "Member");
checkPermission(Permission.VOICE_DEAF_OTHERS);
//We check the owner instead of Position because, apparently, Discord doesn't care about position for
// muting and deafening, only whether the affected Member is the owner.
if (guild.getOwner().equals(member))
throw new HierarchyException("Cannot modify Guild Deafen status the Owner of the Guild");
if (member.getVoiceState().isGuildDeafened() == deafen)
return new AuditableRestAction.EmptyRestAction<>(getJDA(), null);
JSONObject body = new JSONObject().put("deaf", deafen);
Route.CompiledRoute route = Route.Guilds.MODIFY_MEMBER.compile(guild.getId(), member.getUser().getId());
return new AuditableRestAction<Void>(guild.getJDA(), route, body)
{
@Override
protected void handleResponse(Response response, Request<Void> request)
{
if (response.isOk())
request.onSuccess(null);
else
request.onFailure(response);
}
};
}
示例8: setMute
import net.dv8tion.jda.core.requests.restaction.AuditableRestAction; //导入方法依赖的package包/类
/**
* Sets the Guild Muted state state of the {@link net.dv8tion.jda.core.entities.Member Member} based on the provided
* boolean.
*
* <p><b>Note:</b> The Member's {@link net.dv8tion.jda.core.entities.GuildVoiceState#isGuildMuted() GuildVoiceState.isGuildMuted()} value won't change
* until JDA receives the {@link net.dv8tion.jda.core.events.guild.voice.GuildVoiceGuildMuteEvent GuildVoiceGuildMuteEvent} event related to this change.
*
* <p>Possible {@link net.dv8tion.jda.core.requests.ErrorResponse ErrorResponses} caused by
* the returned {@link net.dv8tion.jda.core.requests.RestAction RestAction} include the following:
* <ul>
* <li>{@link net.dv8tion.jda.core.requests.ErrorResponse#MISSING_PERMISSIONS MISSING_PERMISSIONS}
* <br>The target Member cannot be muted due to a permission discrepancy</li>
*
* <li>{@link net.dv8tion.jda.core.requests.ErrorResponse#MISSING_ACCESS MISSING_ACCESS}
* <br>We were removed from the Guild before finishing the task</li>
*
* <li>{@link net.dv8tion.jda.core.requests.ErrorResponse#UNKNOWN_MEMBER UNKNOWN_MEMBER}
* <br>The specified Member was removed from the Guild before finishing the task</li>
* </ul>
*
* @param member
* The {@link net.dv8tion.jda.core.entities.Member Member} who's {@link GuildVoiceState VoiceState} is being changed.
* @param mute
* Whether this {@link net.dv8tion.jda.core.entities.Member Member} should be muted or unmuted.
*
* @throws net.dv8tion.jda.core.exceptions.InsufficientPermissionException
* If the logged in account does not have the {@link net.dv8tion.jda.core.Permission#VOICE_DEAF_OTHERS} permission.
* @throws net.dv8tion.jda.core.exceptions.HierarchyException
* If the provided member is the Guild's owner. You cannot modify the owner of a Guild.
* @throws java.lang.IllegalArgumentException
* If the provided member is not from this Guild or null.
* @throws net.dv8tion.jda.core.exceptions.GuildUnavailableException
* If the guild is temporarily not {@link net.dv8tion.jda.core.entities.Guild#isAvailable() available}
*
* @return {@link net.dv8tion.jda.core.requests.restaction.AuditableRestAction AuditableRestAction}
*/
@CheckReturnValue
public AuditableRestAction<Void> setMute(Member member, boolean mute)
{
checkAvailable();
Checks.notNull(member, "Member");
checkGuild(member.getGuild(), "Member");
checkPermission(Permission.VOICE_MUTE_OTHERS);
//We check the owner instead of Position because, apparently, Discord doesn't care about position for
// muting and deafening, only whether the affected Member is the owner.
if (guild.getOwner().equals(member))
throw new HierarchyException("Cannot modify Guild Mute status the Owner of the Guild");
if (member.getVoiceState().isGuildMuted() == mute)
return new AuditableRestAction.EmptyRestAction<>(getJDA(), null);
JSONObject body = new JSONObject().put("mute", mute);
Route.CompiledRoute route = Route.Guilds.MODIFY_MEMBER.compile(guild.getId(), member.getUser().getId());
return new AuditableRestAction<Void>(guild.getJDA(), route, body)
{
@Override
protected void handleResponse(Response response, Request<Void> request)
{
if (response.isOk())
request.onSuccess(null);
else
request.onFailure(response);
}
};
}