简体   繁体   中英

IntelliJ Could not set unknown property 'mainClassName' for root project 'Blue Bot' of type org.gradle.api.Project

I am following a tutorial to make a basic Discord Bot, ( https://medium.com/discord-bots/making-a-basic-discord-bot-with-java-834949008c2b ) and i got the error, Could not set unknown property 'mainClassName' for root project 'Blue Bot' of type org.gradle.api.Project and I don't know how to fix it. Here is my build.grade code

plugins {
    id 'java'
}
mainClassName = "Main"
group 'BlueBot'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
    jcenter()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
    compile 'net.dv8tion:JDA:4.0.0_62'
}

and here is my Main.java code

import net.dv8tion.jda.api.AccountType;
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;

import javax.security.auth.login.LoginException;


public class Main extends ListenerAdapter {
    public static void main(String[] args) throws LoginException {
        JDABuilder builder = new JDABuilder(AccountType.BOT);
        String token = "enter token here";
        builder.setToken(token);
        builder.addEventListeners(new Main());
        builder.build();
    }

    @Override
    public void onMessageReceived(MessageReceivedEvent event) {
        System.out.println("We received a message from " +
                event.getAuthor().getName() + ": " +
                event.getMessage().getContentDisplay()
        );

        if (event.getMessage().getContentRaw().equals("I am lonely")) {
            event.getChannel().sendMessage("Who isn't?").queue();
        }
    }
}

Let me know if you need more info.

You need to apply the application plugin:

plugins {
    id 'application'
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM