Java源码示例:net.dv8tion.jda.api.events.guild.member.GuildMemberRemoveEvent
示例1
@Override
public void onEvent(@Nonnull GenericEvent event) {
if (event instanceof GuildMemberJoinEvent) {
this.onGuildMemberJoin((GuildMemberJoinEvent) event);
} else if (event instanceof GuildMemberRemoveEvent) {
this.onGuildMemberRemove((GuildMemberRemoveEvent) event);
} else if (event instanceof GuildMemberRoleRemoveEvent) {
this.onGuildMemberRoleRemove((GuildMemberRoleRemoveEvent) event);
} else if (event instanceof GuildMemberRoleAddEvent) {
this.onGuildMemberRoleAdd((GuildMemberRoleAddEvent) event);
}
}
示例2
private void onGuildMemberRemove(GuildMemberRemoveEvent event) {
final Guild guild = event.getGuild();
final User user = event.getUser();
final SelfUser selfUser = event.getJDA().getSelfUser();
// If we are leaving we need to ignore this as we cannot send messages to any channels
// when this event is fired
if (user.equals(selfUser)) {
return;
}
final GuildSettings settings = GuildSettingsUtils.getGuild(guild, variables);
// If the leave message is enabled and we have a welcome channel
if (settings.isEnableJoinMessage() && settings.getWelcomeLeaveChannel() > 0) {
final long welcomeLeaveChannelId = settings.getWelcomeLeaveChannel();
final TextChannel welcomeLeaveChannel = guild.getTextChannelById(welcomeLeaveChannelId);
final String msg = parseGuildVars(settings.getCustomLeaveMessage(), event);
// If we have a message and the text channel is not null
if (!msg.isEmpty() && !"".equals(msg.trim()) && welcomeLeaveChannel != null) {
sendMsg(welcomeLeaveChannel, msg);
}
}
if (guild.getIdLong() == Settings.SUPPORT_GUILD_ID) {
handlePatronRemoval(user.getIdLong());
}
}
示例3
@Nonnull
private String parseGuildVars(String rawMessage, GenericGuildEvent event) {
if (!(event instanceof GuildMemberJoinEvent) && !(event instanceof GuildMemberRemoveEvent)) {
return "This code should never run";
}
if (rawMessage == null || "".equals(rawMessage.trim())) {
return "";
}
final User user;
if (event instanceof GuildMemberJoinEvent) {
user = ((GuildMemberJoinEvent) event).getUser();
} else {
user = ((GuildMemberRemoveEvent) event).getUser();
}
final Guild guild = event.getGuild();
final GuildSettings s = GuildSettingsUtils.getGuild(guild, variables);
final long welcomeLeaveChannel = s.getWelcomeLeaveChannel();
final Parser parser = CommandUtils.PARSER_SUPPLIER.get();
final String message = parser.put("user", user)
.put("guild", event.getGuild())
.put("channel", event.getGuild().getTextChannelById(welcomeLeaveChannel))
.put("args", "")
.parse(rawMessage);
parser.clear();
return message;
}