0

discordbotlist.com POST example

Free lines JavaScript 2 revisions 32 16 days ago 16 days ago
// Require node-fetch
const fetch = require("node-fetch");

// Make your post request to discordbotlist.com
fetch(`https://discordbotlist.com/api/bots/${bot.user.id}/stats`, {
   method: "POST",
   headers: {
      Authorization: `Bot <your-token>`, // Make sure to replace <your-token> with your actual token.
      "Content-Type": "application/json",
      Accept: "application/json"
   },
   body: JSON.stringify({
      shard_id: bot.shard ? bot.shard.count : 0, // Or `bot.shards.size` on Eris
      voice_connections: bot.voice ? bot.voice.connections.size, // Or `bot.voiceConnections.size` on eris. In Discord.js stable, use `bot.voiceConnections.size` instead
      guilds: bot.guilds.size, // `guilds` and `users` may not be accurate depending on how many shards you have (Discord.js). You'll have to get them all with broadcastEval
      users: bot.guilds.reduce((prev, now) => prev + now.memberCount, 0)
   })
}).then((res) => res.text());

This small snippet is a simple example for how to post to https://discordbotlist.com. It's made to work with both Eris and Discord.js, however, Discord.js with its sharding and stable/master may require you change some bits.

Made by PostFarmer#0001.