JDA 抓取 Discord Forum Channel 內的 Thread 清單

Code 範例

public class Main extends ListenerAdapter {

    public static final String TOKEN = "<BOT_TOKEN_HERE>";
    public static final String SERVER_ID = "<SERVER_ID_HERE>";
    public static final String PROJECT_FORUM_ID = "<FORUM_ID_HERE>";

    public static void main(String[] args) throws InterruptedException {
        JDA jda = JDABuilder.createDefault(Main.TOKEN).build();

        jda.addEventListener(new Main());
    }

    @Override
    public void onReady(ReadyEvent event) {
        System.out.println("Bot is ready");
        JDA jda = event.getJDA();

        Guild server = jda.getGuildById(SERVER_ID);
        assert server != null;
        ForumChannel channel  = server.getForumChannelById(PROJECT_FORUM_ID);
        assert channel != null;
        System.out.printf("Channel name: %s%n", channel.getName());
        List<ThreadChannel> threadChannels = channel.getThreadChannels();

        for(ThreadChannel thread : threadChannels){
            System.out.printf("Thread: %s%n", thread.getName());
        }
//        如果要正常關閉 Bot 的話需要以下指令
//        jda.shutdown();
    }
}

解釋

注意


Revision #1
Created 31 July 2023 14:38:02 by Nesquate
Updated 28 June 2024 05:54:38 by Nesquate