【发布时间】:2019-11-10 11:47:48
【问题描述】:
我正在为我的 Discord 机器人设置一个 SQLite,我想为每个服务器创建一个带有服务器名称的数据库文件,但我找不到每个服务器的公会
我有一个类来创建与 sql 和 main 的连接,创建连接的方法效果很好,但我只需要为每个服务器创建一个 db 文件
这是我的 SQLite 连接类:
package LiteSQL;
import java.io.File;
import java.io.IOException;
import java.sql.*;
public class LiteSQL {
private static Connection con;
private static Statement stmt;
public static void connect(String serverName){
con=null;
try{
File file = new File(serverName+".db");
if(!file.exists())
file.createNewFile();
String url="jdbc:sqlite:"+file.getPath();
con = DriverManager.getConnection(url);
stmt = con.createStatement();
System.out.println("SQL Connected");
}catch(SQLException | IOException e){
e.printStackTrace();
}
}
public static void disconnect(){
try{
if(con!=null) {
con.close();
System.out.println("Disconnected from SQL");
}
}catch(SQLException e){
e.printStackTrace();
}
}
public static void onUpdate(String sql){
try{
stmt.execute(sql);
}catch(SQLException e){
e.printStackTrace();
}
}
public static ResultSet onQury(String sql){
try{
return stmt.executeQuery(sql);
}catch(SQLException e){
e.printStackTrace();
}
return null;
}
}
这是我的主要方法
package Main;
import Commands.*;
import Commands.AdminCommands.Clear;
import Commands.AdminCommands.Verify;
import Commands.AdminCommands.mute;
import Commands.AdminCommands.unmute;
import Commands.Music.*;
import Events.MemberJoin;
import Events.MemberLeave;
import Events.Reactions;
import LiteSQL.LiteSQL;
import net.dv8tion.jda.core.AccountType;
import net.dv8tion.jda.core.JDA;
import net.dv8tion.jda.core.JDABuilder;
import net.dv8tion.jda.core.entities.Game;
import net.dv8tion.jda.core.entities.Guild;
public class Bot {
public static final String prefix = "~";
public static JDA jda;
public static void main(String[] args) throws Exception{
LiteSQL.connect(I need to put here the servers' names);
jda = new
JDABuilder(AccountType.BOT).setToken("NTkzMDgwMjIyMDMxNTQ0MzIx.XRI0wA.2TKzqfhrimbdip684e30QfFhMK8").build();
jda.getPresence().setGame(Game.playing("Java Version bot '~' prefix"));
}
}
在线LiteSQL.connect(I need to put here the servers' names);
我需要将我的机器人连接到的每个服务器名称都放入
【问题讨论】:
-
恭喜您的登录令牌泄露。现在继续并重新生成它。
-
已经做到了,不用担心 thx
标签: java discord-jda