当我禁止该成员时,他们没有在那里发送消息,甚至认为用户 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);
}
错误消息说即使有 dms 已打开,它也无法 dm 用户