在我目前的Discord(java)bot中尝试将命令应用于用户名。我怎样才能确保这是一个真正的现有用户?
在伪代码中:
if User "A" exists {
User "A" types something at all
send message "hello"+ user "A"
}
else
{
this is no valid user;
}
我无法弄清楚如何编写'检查是否存在代码'。
答案 0 :(得分:0)
这来自JDA-Utilities,它是构建不和谐机器人时非常有用的工具。
import com.jagrosh.jdautilities.command.Command;
import com.jagrosh.jdautilities.command.CommandEvent;
public class Example extends Command {
public Example() {
this.name = "'isBot";
this.help = "Tells you if the user is a bot!";
}
@Override
protected void execute(CommandEvent e) {
if (e.getAuthor().isBot()) {
e.reply("Hey you're not a person!!");
} else {
e.reply("Hey " + e.getAuthor().getName() + ", you're not a bot!");
}
}
}