Closed ghost closed 3 years ago
I tried it with maven and gradle (Build > Build Artifact > Build)
Do you mind showing some code snippets?
yes
public Selfy(String name, String version, String prefix, String token, ArrayList<String> developers, me.sirlennox.selfy.AccountType accountType) {
this.NAME = name;
this.VERSION = version;
this.PREFIX = prefix;
this.TOKEN = token;
this.DEVELOPERS = developers;
this.commandManager = new CommandManager();
this.moduleManager = new ModuleManager();
this.API = addEventListeners(buildBot(token));
this.accountType = accountType;
}
public DiscordApi addEventListeners(DiscordApi api) {
api.addMessageCreateListener(event -> {
if(event.getMessage().getAuthor().getId() == api.getYourself().getId()) {
String msg = event.getMessageContent();
if(msg.startsWith(PREFIX)) {
String msgWithoutPrefix = msg.substring(PREFIX.length());
String[] args = new String[msgWithoutPrefix.split(" ").length - 1];
for(int i = 1; i < msgWithoutPrefix.split(" ").length; i++) {
args[i - 1] = msgWithoutPrefix.split(" ")[i];
}
String c = msgWithoutPrefix.split(" ")[0];
for(Command cmd : this.commandManager.commands) {
if(cmd.cmd.equalsIgnoreCase(c) || isAliasOfCommand(cmd, c)) {
if(cmd.onlyPremium && !Utils.hasAccessToPremiumFeatures()) {
MessageUtils.editMessage("Error", "This command is premium only and you don't have premium!", Color.RED.getRGB(), event.getMessage());
return;
}
cmd.onCommand(args, event);
return;
}
}
}
}
});
return api;
}
public DiscordApi buildBot(String token) {
return new DiscordApiBuilder().setAccountType(AccountType.CLIENT).setToken(token).login().join();
}
You probably try to build a fat jar and do it wrongly, which is one of the reasons fat jars are evil.
You miss the javacord-core artifact in your fat jar, or at least the relevant files from META-INF
.
As you mentioned Gradle, I'd strongly recommend building a proper distribution instead, by applying the application
plugin. Then (and after configuring the main class properly) you can use distTar
or distZip
to create a distributable archive with everyting you need and nifty start scripts in the bin
directory of that archive.
I have javacord-core and in my META-INF is only a MANIFEST.MF
so is this wrong?
Yes, that is wrong
Btw. you are trying to build a self-bot, that is a violation of the Discord ToS, will in near future be removed from Javacord completely and is already broken in large parts already due to incompatible changes on Discord side.
Ok, and what do I have to put into my META-INF?
The javacord-core artifact has files in there in services
that are essential.
If you repack the artifact but leave out those files, you should not wonder that it does not work.
That's one of the reasons fat jars are evil, you are modifying libraries in unsupported ways and then go to the maintainers and complain that their library does not work, while you actively broke it by manipulating the files. ;-)
Thank you very much, it worked fine. Please stay supporting selfbots, because there aren't any java libraries with selfbot support, and I like java (I don't want to switch to python) :)
Hello, I was trying to create a discord bot. In my IDE it worked fine but as I exported it there was an error:
I hope you can help me, thanks :)