为什么我的命令没有运行?
我有一个命令(〜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;
}
}
这是我的命令:
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();
}
}
答案 0 :(得分:1)
两件事:
if(!memb.getRoles().contains(role)) {
而不是if(memb.getRoles().contains(role)) {
,因为似乎您要搜索的用户没有静音角色。 (这就是您的命令似乎正在执行的操作)。目前,您的命令仅在搜索确实具有该角色的用户。"SELECT userid, guildid FROM timeranks WHERE ((julianday(CURRENT_TIMESTAMP) - julianday(time)) /1000 /60) >= 15"
而不是{{1 }}。这将使其仅对时间大于15分钟而不是大于0.015毫秒的用户激活。