简体   繁体   English

如何添加多个前缀 - JDA

[英]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?我想知道如何为我的 discord 机器人添加多个前缀?

This is my current prefix listener code, the prefix is being pulled from a.env这是我当前的前缀侦听器代码,前缀是从 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.目前我的机器人的前缀是基于提及<@,ID>,但这种类型的提及不适用于移动 discord(移动 discord 仅使用 <@ID> 进行提及,没有“.”),所以我想添加要在我的机器人上使用的两种变体。

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) {
    //...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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