Java Timerank命令在没有任何错误的情况下无法工作

Java Timerank命令在没有任何错误的情况下无法工作,java,discord,discord-jda,Java,Discord,Discord Jda,为什么我的命令没有运行 我有一个discord bot命令(~timerank@user)。bot应该给用户一个角色。。但是命令没有运行。编译时我没有收到任何错误。我像所有其他命令一样注册了我的命令: public class CommandManager { public ConcurrentHashMap<String, ServerCommand> commands; public CommandManager() { this.comman

为什么我的命令没有运行

我有一个discord bot命令(~timerank@user)。bot应该给用户一个角色。。但是命令没有运行。编译时我没有收到任何错误。我像所有其他命令一样注册了我的命令:

public class CommandManager {

    public ConcurrentHashMap<String, ServerCommand> commands;
    public CommandManager() {

        this.commands = new ConcurrentHashMap<>();

        this.commands.put("clear", new ClearCommand());
        this.commands.put("preview", new PreviewCommand());
        this.commands.put("client", new ClientInfoCommand());
        this.commands.put("help", new HelpCommand());
        this.commands.put("vote", new VoteCommand());
        this.commands.put("play", new PlayCommand());
        this.commands.put("stop", new StopCommand());
        this.commands.put("trackinfo", new TrackInfoCommand());
        this.commands.put("shuffle", new ShuffleCommand());
        this.commands.put("statchannel", new StatChannelCommand());
        this.commands.put("timerank", new TimeRankCommand());
    }

    public boolean perform(String command, Member m, TextChannel channel, Message message, MessageReceivedEvent event) {

        ServerCommand cmd;

        if((cmd = this.commands.get(command.toLowerCase())) != null) {
            cmd.performCommand(m, channel, message, event);
            return true;
        }
        return false;
    }
}
有人知道为什么命令没有运行吗?如果是SQL问题,我至少会在函数中得到消息

顺便说一句,这是我在15分钟后删除角色的函数。(该函数总是在1分钟后调用):

两件事:

  • 我认为if语句中的代码应该是
    if(!memb.getRoles().contains(role)){
    而不是
    if(memb.getRoles().contains(role)){
    ,因为您似乎希望搜索没有静音角色的用户。(这就是您的命令所做的)当前,您的命令仅搜索具有该角色的用户
  • 我不熟悉SQLite是如何存储时间戳的,但如果它的工作方式与其他系统存储时间戳的方式相同(它可能会这样做),那么您需要执行
    “选择userid,guildid FROM timeranks,其中((julianday(CURRENT_TIMESTAMP)-julianday(time))/1000/60)>=15”
    而不是
    “从时间等级中选择userid,guildid,其中((julianday(当前时间戳)-julianday(时间))*1000)>=15”
    。这将使其仅对时间大于15分钟而不是大于0.015毫秒的用户激活。”
  • public class TimeRankCommand implements ServerCommand {
    
        @Override
        public void performCommand(Member m, TextChannel channel, Message message, MessageReceivedEvent event) {
    
            //~timerank @User
            if (m.hasPermission(Permission.ADMINISTRATOR)) {
                List<Member> members = message.getMentionedMembers();
    
                if(members.size() >= 1) {
                    for(Member memb : members) {
    
                        Guild guild = channel.getGuild();
                        Role role = guild.getRoleById(648047607486087168l);
    
                        if(memb.getRoles().contains(role)) {
    
                            guild.addRoleToMember(memb, role).queue();
    
                            LiteSQL.onUpdate("INSERT INTO timeranks(userid, guildid) VALUES(" + memb.getIdLong() + ", " + guild.getIdLong() + ")");
    
                            EmbedBuilder builder = new EmbedBuilder();
                            builder.setTitle("Timerank");
                            builder.setThumbnail("http://i.epvpimg.com/toDBaab.png");
                            builder.setFooter("Powered by Backxtar.");
                            builder.setTimestamp(OffsetDateTime.now());
                            builder.setColor(0xf22613);
                            builder.setDescription(memb.getAsMention() + " is **MUTED** for 15 minutes!");
                            channel.sendMessage(builder.build()).queue();
                        }
                    }
                }
            }
        }
    }
    
    public class SQLManager {
    
        public static void onCreate() {
    
            //TimeRank
            LiteSQL.onUpdate("CREATE TABLE IF NOT EXISTS timeranks(id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, userid INTEGER, guildid INTEGER, time TIMESTAMP DEFAULT CURRENT_TIMESTAMP)");
        }
    
    }
    
    public void onCheckTimeRanks() {
            ResultSet set = LiteSQL.onQuery("SELECT userid, guildid FROM timeranks WHERE ((julianday(CURRENT_TIMESTAMP) - julianday(time)) * 1000) >= 15");
    
            try {
                while(set.next()) {
                    long userid = set.getLong("userid");
                    long guildid = set.getLong("guildid");
    
                    Guild guild = this.shardMan.getGuildById(guildid);
                    guild.removeRoleFromMember(guild.getMemberById(userid), guild.getRoleById(648047607486087168l)).complete();
    
                    LiteSQL.onUpdate("DELETE FROM timeranks WHERE userid = " + userid);
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }