gpt4 book ai didi

java - Timerank 命令无法正常工作,没有任何错误

转载 作者:行者123 更新时间:2023-12-02 09:15:23 26 4
gpt4 key购买 nike

为什么我的命令没有运行?

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

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;
}
}

这是我的命令:

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();
}
}
}
}
}
}

这是我的 SQLManager:

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)");
}

}

有人知道为什么该命令没有运行吗?如果它是一个 SQL 问题,我至少会在函数中得到消息..

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

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();
}
}

最佳答案

有两件事:

  1. 我相信 if 语句中的代码应该是 if(!memb.getRoles().contains(role)) { 而不是 if(memb.getRoles().contains( role)) {,因为您似乎想要搜索没有静音角色的用户。 (这似乎就是您的命令正在执行的操作)当前,您的命令仅搜索具有该角色的用户。
  2. 我不熟悉 SQLite 如何存储时间戳,但如果它的工作方式与其他每个系统存储时间戳的方式相同(它可能会这样做),那么您应该执行 "SELECT userid, guildid FROM timeranks WHERE ((julianday(CURRENT_TIMESTAMP) - julianday(time))/1000/60) >= 15" 而不是 "SELECT userid, guildid FROM timeranks WHERE ((julianday(CURRENT_TIMESTAMP) - julianday(time)) ) * 1000) >= 15"。这将使其仅对时间大于 15 分钟(而不是大于 0.015 毫秒)的用户激活。

关于java - Timerank 命令无法正常工作,没有任何错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59038714/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com