Users will receive news & member role on join, added welcome channel. Added aliasses to the SuggestCommand
This commit is contained in:
parent
3e717de947
commit
81a2459f89
@ -6,7 +6,7 @@ import java.util.Calendar;
|
|||||||
* @author Nicholas
|
* @author Nicholas
|
||||||
*/
|
*/
|
||||||
public class BotConstants {
|
public class BotConstants {
|
||||||
public static final String TOKEN = "ODA5NjMxMzcxNzg1Nzk3NjMz.YCX5-Q.t4S8qOmhAc98DKKw9rBsPNv82xM";
|
public static final String TOKEN = "NzY1NTI5MTM2NzgxMDY2MjQ2.X4WIkQ.L7pszAdOq1cbqwyhxtr_-qBULpA";
|
||||||
public static final String PREFIX = ".";
|
public static final String PREFIX = ".";
|
||||||
|
|
||||||
public static final String OWNER_ID = "504069946528104471"; // Joel
|
public static final String OWNER_ID = "504069946528104471"; // Joel
|
||||||
|
@ -9,6 +9,8 @@ import net.dv8tion.jda.api.entities.Activity;
|
|||||||
import net.dv8tion.jda.api.requests.GatewayIntent;
|
import net.dv8tion.jda.api.requests.GatewayIntent;
|
||||||
import zone.themcgamer.discordbot.command.impl.SetActivityCommand;
|
import zone.themcgamer.discordbot.command.impl.SetActivityCommand;
|
||||||
import zone.themcgamer.discordbot.command.impl.SuggestCommand;
|
import zone.themcgamer.discordbot.command.impl.SuggestCommand;
|
||||||
|
import zone.themcgamer.discordbot.command.impl.ToggleNewsRoleCommand;
|
||||||
|
import zone.themcgamer.discordbot.events.GuildMemberJoinQuitListener;
|
||||||
|
|
||||||
import javax.security.auth.login.LoginException;
|
import javax.security.auth.login.LoginException;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
@ -34,6 +36,7 @@ public class MGZBot {
|
|||||||
|
|
||||||
commandClientBuilder.addCommand(new SuggestCommand());
|
commandClientBuilder.addCommand(new SuggestCommand());
|
||||||
commandClientBuilder.addCommand(new SetActivityCommand());
|
commandClientBuilder.addCommand(new SetActivityCommand());
|
||||||
|
commandClientBuilder.addCommand(new ToggleNewsRoleCommand());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
jda = JDABuilder.createDefault(BotConstants.TOKEN)
|
jda = JDABuilder.createDefault(BotConstants.TOKEN)
|
||||||
@ -41,7 +44,9 @@ public class MGZBot {
|
|||||||
.setActivity(Activity.playing("Booting up..."))
|
.setActivity(Activity.playing("Booting up..."))
|
||||||
.setStatus(OnlineStatus.IDLE)
|
.setStatus(OnlineStatus.IDLE)
|
||||||
.enableIntents(GatewayIntent.GUILD_MEMBERS, GatewayIntent.GUILD_EMOJIS)
|
.enableIntents(GatewayIntent.GUILD_MEMBERS, GatewayIntent.GUILD_EMOJIS)
|
||||||
.addEventListeners(commandClientBuilder.build())
|
.addEventListeners(
|
||||||
|
commandClientBuilder.build(),
|
||||||
|
new GuildMemberJoinQuitListener(this))
|
||||||
.build();
|
.build();
|
||||||
jda.awaitReady();
|
jda.awaitReady();
|
||||||
} catch (LoginException | InterruptedException ex) {
|
} catch (LoginException | InterruptedException ex) {
|
||||||
|
@ -18,6 +18,7 @@ import java.util.stream.Collectors;
|
|||||||
public class SuggestCommand extends BaseCommand {
|
public class SuggestCommand extends BaseCommand {
|
||||||
public SuggestCommand() {
|
public SuggestCommand() {
|
||||||
name = "suggest";
|
name = "suggest";
|
||||||
|
aliases = new String[]{"suggestion"};
|
||||||
help = "Share a suggestion!";
|
help = "Share a suggestion!";
|
||||||
arguments = "<suggestion>";
|
arguments = "<suggestion>";
|
||||||
guildOnly = true;
|
guildOnly = true;
|
||||||
|
47
discordbot/src/main/java/zone/themcgamer/discordbot/command/impl/ToggleNewsRoleCommand.java
Normal file
47
discordbot/src/main/java/zone/themcgamer/discordbot/command/impl/ToggleNewsRoleCommand.java
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
package zone.themcgamer.discordbot.command.impl;
|
||||||
|
|
||||||
|
import com.jagrosh.jdautilities.command.CommandEvent;
|
||||||
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
|
import net.dv8tion.jda.api.entities.Guild;
|
||||||
|
import net.dv8tion.jda.api.entities.Member;
|
||||||
|
import net.dv8tion.jda.api.entities.Role;
|
||||||
|
import zone.themcgamer.discordbot.command.BaseCommand;
|
||||||
|
import zone.themcgamer.discordbot.utilities.EmbedUtils;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ToggleNewsRoleCommand extends BaseCommand {
|
||||||
|
|
||||||
|
public ToggleNewsRoleCommand() {
|
||||||
|
name = "togglenews";
|
||||||
|
aliases = new String[]{"news"};
|
||||||
|
help = "Turn on or off news role.";
|
||||||
|
guildOnly = true;
|
||||||
|
guilds = Collections.singletonList(zone.themcgamer.discordbot.guild.Guild.MAIN);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void execute(CommandEvent event, List<String> args) {
|
||||||
|
Member member = event.getMember();
|
||||||
|
Guild guild = event.getGuild();
|
||||||
|
if (member == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Role newsRole = guild.getRoleById(812440883898875914L);
|
||||||
|
if (newsRole == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (member.getRoles().contains(newsRole)) {
|
||||||
|
guild.removeRoleFromMember(member.getIdLong(), newsRole).queue();
|
||||||
|
EmbedBuilder embedBuilder = EmbedUtils.successEmbed();
|
||||||
|
embedBuilder.setDescription("You have successfully removed the " + newsRole.getAsMention() + " role from your account!");
|
||||||
|
event.reply(embedBuilder.build());
|
||||||
|
} else {
|
||||||
|
guild.addRoleToMember(member.getIdLong(), newsRole).queue();
|
||||||
|
EmbedBuilder embedBuilder = EmbedUtils.successEmbed();
|
||||||
|
embedBuilder.setDescription("You have successfully added the " + newsRole.getAsMention() + " role to your account!");
|
||||||
|
event.reply(embedBuilder.build());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
66
discordbot/src/main/java/zone/themcgamer/discordbot/events/GuildMemberJoinQuitListener.java
Normal file
66
discordbot/src/main/java/zone/themcgamer/discordbot/events/GuildMemberJoinQuitListener.java
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
package zone.themcgamer.discordbot.events;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
|
import net.dv8tion.jda.api.entities.Guild;
|
||||||
|
import net.dv8tion.jda.api.entities.Role;
|
||||||
|
import net.dv8tion.jda.api.entities.TextChannel;
|
||||||
|
import net.dv8tion.jda.api.entities.User;
|
||||||
|
import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent;
|
||||||
|
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||||
|
import zone.themcgamer.discordbot.BotConstants;
|
||||||
|
import zone.themcgamer.discordbot.MGZBot;
|
||||||
|
import zone.themcgamer.discordbot.utilities.EmbedUtils;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class GuildMemberJoinQuitListener extends ListenerAdapter {
|
||||||
|
private final MGZBot mgzBot;
|
||||||
|
@Override
|
||||||
|
public void onGuildMemberJoin(@Nonnull GuildMemberJoinEvent event) {
|
||||||
|
User user = event.getUser();
|
||||||
|
Guild guild = event.getGuild();
|
||||||
|
if (user.isBot())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (guild.getId().equals(BotConstants.MAIN_GUILD_ID)) {
|
||||||
|
Role memberRole = guild.getRoleById(793672609395900446L);
|
||||||
|
if (memberRole != null)
|
||||||
|
guild.addRoleToMember(user.getId(), memberRole).queue();
|
||||||
|
Role newsRole = guild.getRoleById(812440883898875914L);
|
||||||
|
if (newsRole != null)
|
||||||
|
guild.addRoleToMember(user.getId(), newsRole).queue();
|
||||||
|
|
||||||
|
user.openPrivateChannel().queue(privateChannel -> {
|
||||||
|
EmbedBuilder embedBuilder = EmbedUtils.defaultEmbed();
|
||||||
|
embedBuilder.setThumbnail(mgzBot.getJda().getSelfUser().getAvatarUrl());
|
||||||
|
embedBuilder.setDescription("Welcome to **McGamerZone** you have received News & Member role.");
|
||||||
|
privateChannel.sendMessage(embedBuilder.build()).queue();
|
||||||
|
}, error -> {
|
||||||
|
TextChannel textChannelById = guild.getTextChannelById(767396615299923998L);
|
||||||
|
if (textChannelById != null)
|
||||||
|
textChannelById.sendMessage(user.getAsMention() + ", I could not sent a message to you due you have private messages disabled!").queue();
|
||||||
|
});
|
||||||
|
|
||||||
|
TextChannel textChannelById = guild.getTextChannelById(812453030405996564L);
|
||||||
|
if (textChannelById == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
EmbedBuilder embedBuilder = EmbedUtils.defaultEmbed();
|
||||||
|
embedBuilder.setTitle("Welcome to McGamerZone, " + user.getAsTag());
|
||||||
|
embedBuilder.setThumbnail(user.getAvatarUrl());
|
||||||
|
embedBuilder.setDescription("This is the official Discord server for McGamerZone Minecraft server." +
|
||||||
|
"We are a fun Server that is focused on creativity, community-building, and keeping to the" +
|
||||||
|
"core of the game itself. Our goal here; is to maintain a friendly, fun, " +
|
||||||
|
"and equal community for anyone and everyone that joins in and " +
|
||||||
|
"give the og players of MGZ the nostalgia feeling back!");
|
||||||
|
embedBuilder.setTimestamp(event.getMember().getTimeJoined());
|
||||||
|
embedBuilder.setFooter("Joined at » ");
|
||||||
|
textChannelById.sendMessage(user.getAsMention()).queue(message -> message.delete().queue());
|
||||||
|
textChannelById.sendMessage(embedBuilder.build()).queue(message -> {
|
||||||
|
message.addReaction(":MGZ_Icon_M:791020631042162729").queue();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user