如何从Discord Webhook API使用EmbedObject

时间:2019-02-04 13:53:56

标签: java

好吧,我正在使用https://gist.github.com/k3kdude/fba6f6b37594eae3d6f9475330733bdb API,但是当我尝试在Mainclass上创建EmdedObject时,它将无法正常工作,始终为NullPointerException

因此,我想通过Webhook向Discord发送消息,而我已经尝试了EmbedObject a。但是它只是说不能那样导入。

MainClass.java:

    public static DiscordWebhook dwh;
        dwh = new DiscordWebhook("https://canary.discordapp.com/api/webhooks/AAAAAA/AAAAAAA");
        dwh.setAvatarUrl("https://pbs.twimg.com/profile_images/774033927476420608/ALqUMZi1_400x400.jpg");
        dwh.setUsername("LR-BotTest");

    public static void whenDone() throws InterruptedException, IOException {
        for(Map.Entry<String, String> entry : botstatus.entrySet()) {
            String key = entry.getKey(); //RobotID
            String value = entry.getValue(); //State on/off
            System.out.println("1" + value + key);
            DiscordWebhook.EmbedObject a = null;
            a.setTitle("test");

            if(value.equalsIgnoreCase("online")) {
                dwh.addEmbed(a);
//              dwh.setContent("" + botowner.get(key) + " just went live with " + botnames.get(key) + " https://letsrobot.tv/robocaster/" + botowner.get(key) + "/robot/" + key);
                dwh.execute();
                TimeUnit.SECONDS.sleep(1);
            }
            System.out.println("2" + value + key);
        }
    }

DiscordWebhook.java:
https://gist.github.com/k3kdude/fba6f6b37594eae3d6f9475330733bdb

带有显示的代码:

Exception in thread "main" java.lang.NullPointerException
    at ReadJSON.whenDone(ReadJSON.java:61)
    at ReadJSON.main(ReadJSON.java:52)

0 个答案:

没有答案