当我封禁该成员时,他们在DMS中没有消息,即使用户的dm是打开的。
代码在这里
public static void kickUser(@NotNull Member member, @NotNull Member author,
@NotNull String reason, long userId, @NotNull SlashCommandEvent event) {
String guildName = event.getGuild().getName();
event.getJDA()
.openPrivateChannelById(userId)
.flatMap(channel -> channel.sendMessage(
"""
Hey there, sorry to tell you but unfortunately you have been kicked from the guild %s.
If you think this was a mistake, please contact a moderator or admin of the guild.
he reason for the kick is: %s
"""
.formatted(guildName, reason)))
.queue(null,
throwable -> logger.info(
"I could not dm the user '{}' to inform them that they were kicked. {}",
userId, throwable));
event.getGuild()
.kick(member, reason)
.flatMap(v -> event.reply(member.getUser().getAsTag() + " was kicked by "
+ author.getUser().getAsTag() + " for: " + reason))
.queue();
logger.info(" '{} ({})' kicked the user '{} ({})' due to reason being '{}'",
author.getUser().getAsTag(), author.getIdLong(), member.getUser().getAsTag(),
userId, reason);
}
错误信息说它不能dm用户,即使有DMS打开
如果您与用户共享服务器并且用户没有阻止您,则只能发送直接消息。您需要在禁止/踢用户之前发送直接消息。
的例子:
user.openPrivateChannel()
.flatMap(channel -> channel.sendMessage("you are banned")) // send a message to the channel
.mapToResult() // this means the next flatMap runs on success and error signals
.flatMap(result -> guild.ban(member)) // then ban the member
.queue(); // queue the chain of actions