Skip to content

Instantly share code, notes, and snippets.

@shikhir-arora
Created July 5, 2018 12:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shikhir-arora/5a6dfa77d2a9883c5657f70ed824a976 to your computer and use it in GitHub Desktop.
Save shikhir-arora/5a6dfa77d2a9883c5657f70ed824a976 to your computer and use it in GitHub Desktop.

Async, non-blocking post to multiple Discord Bot stats using axios and ES8 async/await.

/**

This is just a snippet (assumes you've defined a Discord client, etc) 

**/



async function postDiscordStats() {
    const discordBots = axios({
        method: 'post',
        url: `https://discordbots.org/api/bots/${client.user.id}/stats`,
        headers: {
            Authorization: ''
        },
        data: {
            server_count: client.guilds.size
        }
    })

    const discordPw = axios({
        method: 'post',
        url: `https://bots.discord.pw/api/bots/${client.user.id}/stats`,
        headers: {
            Authorization: ''
        },
        data: {
            server_count: client.guilds.size
        }
    })

    const botlistSpace = axios({
        method: 'post',
        url: `https://botlist.space/api/bots/${client.user.id}`,
        headers: {
            Authorization: ''
        },
        data: {
            server_count: client.guilds.size
        }
    })

    const discordServices = axios({
        method: 'post',
        url: `https://discord.services/api/bots/${client.user.id}`,
        headers: {
            Authorization: ''
        },
        data: {
            server_count: client.guilds.size
        }
    })

    const [dbres, dpwres, bspaceres, dservres] = await Promise.all([discordBots, discordPw, botlistSpace, discordServices])
    console.log(dbres, dpwres, bspaceres, dservres) // change as desired
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment