简体   繁体   中英

How to fetch data from discord

I would like to know how can I fetch data from discord specifically Number of people in a channel. for example, squad #14 has 3 out of 4 people. I want to fetch that number and display it somewhere in a site. How would I do that?

Regards.

If you are familiar with javascript, I'd recommend discord.js

This library can be run through javascript, as well as node.js.

Discord doesn't provide an official way of getting members in a voice channel from the REST API as far as I can tell. To achieve this you will likely need to run a full-blown bot and invite it to your guild. For Java I recommend the JDA library.

public class ReadyListener implements EventListener
{
    public static void main(String[] args)
            throws LoginException, RateLimitedException, InterruptedException
    {
        // Note: It is important to register your ReadyListener before building
        JDA jda = new JDABuilder(AccountType.BOT)
            .setToken("token")
            .addEventListener(new ReadyListener())
            .buildBlocking();
    }

    @Override
    public void onEvent(Event event)
    {
        if (event instanceof ReadyEvent)
        {
            System.out.println("API is ready!");

            // Get a specific voice channel
            event.getJda().getVoiceChannelById("12341234");
        }
    }
}

Recommended reading:

https://github.com/DV8FromTheWorld/JDA/wiki/3)-Getting-Started

https://discordapp.com/developers/docs/intro

You will probably want to look at the VoiceChannel class in the javadocs.

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