如何从discord webhook api使用embedobject

ilmyapht  于 2021-07-09  发布在  Java
关注(0)|答案(0)|浏览(212)

嗯,我用的是https://gist.github.com/k3kdude/fba6f6b37594eae3d6f9475330733bdb api,但当我尝试在main类上创建emdedobject时,它将不起作用,始终是nullpointerexception
所以,我想通过webhook向discord发送一条消息,我已经尝试了嵌入一个对象;但它只是说不能像那样进口。

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)

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题