简体   繁体   中英

how to add more than one prefix - JDA

I would like to know how could I add more than one prefix to my discord bot?

This is my current prefix listener code, the prefix is being pulled from a.env

final long guildId = event.getGuild().getIdLong();
String prefix = Config.get("PREFIX");
String raw = event.getMessage().getContentRaw();

if (raw.startsWith(prefix)) {
    manager.handle(event, prefix);
}

Currently my bot's prefix is based on mention <@,ID>, but this type of mention doesn't work on mobile discord (mobile discord uses only <@ID> for mention, without the "."), so I would like to add both variants to be used on my bot.

I was told I could use regex for that but I have no clue how it works and how to apply it to my code.

Just define a second prefix and check, if the message starts with one of them.

final long guildId = event.getGuild().getIdLong();
String prefix1 = Config.get("PREFIX1");
String prefix2 = Config.get("PREFIX2");
String raw = event.getMessage().getContentRaw();

if (raw.startsWith(prefix1) || raw.startsWith(prefix2) {
    //...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM