简体   繁体   中英

How to get a guild by id with Discord Rest API

I want get a specific discord guild by id for test if my user has permissions to add bot on them guild.

I try with https://discord.com/api/v8/users/@me/guilds and params before and after . But id is snowflake/string and I use nodeJs so it's not possible do: -1.

My current code:

const id = "XXXXXXXXXXX",
      before = id + 1,  // don't work because it's string and big int
      after = id - 1    // same
;

const url = `https://discord.com/api/v8/users/@me/guilds?before=${before}&after=${after}`;


fetch(url, {
    headers: {
        'Authorization': "Bearer XXXXXXXXXXX",
    }
})
.then(res => res.json())
.then(json => console.log(json));

Idea? Thank you.

You should use /guilds/{your guild id here} . This fetches JSON data for a specific guild.

If you would like to find the permissions of the User, try /guilds/{your guild id here}/member/{user}

Examples

Finding a guild:

 const id = "REPLACE_THIS_WITH_YOUR_GUILD", const url = `https://discord.com/api/v9/guilds/`+id; fetch(url, { headers: { 'Authorization': "Bot XXXXXXXXXXX", } }).then(res => res.json()).then(json => console.log(json));

Finding a guild member:

 const id = "XXXXXXXXXXX", const member = '0000000000' const url = `https://discord.com/api/v9/guild/${id}/member/${member}`; fetch(url, { headers: { 'Authorization': "Bot XXXXXXXXXXX", } }).then(res => res.json()).then(json => console.log(json));

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