0
votes

I am creating my first Discord Bot. The bot is for a student society server. I am wanting to assign a role/allow a user join the server based on certain questions.

At the momment, when a new member joins, I send a message in the welcome channel with a welcome message. I also send an Embed with a question. I have it where if they react with thumbs up, it sends another embed asking for their student id. If they thumbs down I send an embed asking if they are student, if they thumb up react then I ask for their student.

How can I get their message and check it equals a String? e.g.(User enters student id: 32984230875 it is then check is equal to string.)

My current reaction listener method:

public void onGuildMessageReactionAdd(GuildMessageReactionAddEvent event) {

    Guild guild = event.getGuild();

    if(event.getMember().equals(member)) {

        if(event.getChannel().getId().equals("ChannelID") && event.getReactionEmote().getName().equals("????")) {
            EmbedBuilder enterStudentID = new EmbedBuilder();
            enterStudentID.setTitle("Enter your Student ID:");

            guild.getTextChannelById("ChannelID").sendMessage(enterStudentID.build()).queue();

        } else {
            EmbedBuilder isMemberStudent = new EmbedBuilder();
            isMemberStudent.setTitle("Are you a Student?");

            guild.getTextChannelById("ChannelID").sendMessage(isMemberStudent.build()).queue(message -> {
                message.addReaction("????").queue();
                message.addReaction("????").queue();
            });

            if(event.getChannel().getId().equals("ChannelID") && event.getReactionEmote().getName().equals("????")) {
                EmbedBuilder enterStudentID = new EmbedBuilder();
                enterStudentID.setTitle("Enter your Student ID:");

                guild.getTextChannelById("channelID").sendMessage(enterStudentID.build()).queue();
            }

        }
    }
}

Ps. First embed asking if they society member, is on member join method. That's what the first react is listening to.

Thanks in advance.

1

1 Answers

0
votes

Every regular message in Discord is a String. The student ID which you need is also a String, but can be converted to a long.

Why not int?
int: uses four bytes to store values from -2,147,483,648 to 2,147,483,647.
long: uses eight bytes to store values from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

So in terms of size, it can only fit into a long.

String myString = "123124";
long myLong;
try {
    myLong = Long.parseLong(myString);
    // You can do more stuff here  
} catch (NumberFormatException ex) {
    ex.printStackTrace();
    // You can do other stuff here to handle the exception.
}

student id: 32984230875

If there's a specific formula for your student ID, let's say every student ID starts with a specific number, and has an exact length, then you can use a Regular expression which validates the provided data against a set of predefined criterion.

So if the String =>> long conversion is successful, or the message matches the regex pattern then the ID is valid for you to use.

EDIT: If I completely misunderstood your problem, then the other thing I can think of is you need to listen for a GuildMessageReceivedEvent, a message which is from the channel which is in use, and from the user who the bot is interacting with.