Vote Webhooks
Give your users rewards for voting for your bot on Botlist.me!
What is a Vote Webhook?
Vote webhooks are HTTP POST requests that get sent to your server whenever someone votes for your bot. These requests are also sent with an authorization header so that you can verify that this request is actually coming from Botlist.me.
You can use vote webhooks to thank your users for voting, remind them to vote again in 12 hours, reward them for voting for your bot or anything else that comes up to your mind.
Warning!
This has nothing to do with discord webhooks. Please do not confuse them!
Example Request Body
Here is an example request body that gets sent when someone votes for your bot.
{
bot: 589901741672103958,
user: 141521475478880256,
type: "Upvote" // Will be set to Test when using the test webhook button
}
Example implementation in node.js
You have 2 options for implementing a vote webhook with node.js. You can use our botlist.me.js
library to implement webhooks or you can use the express
module to create a webserver. Both options have template code available below.
Using botlist.me.js
First you need to install botlist.me.js using one of the following commands depending on your package manager;
If using npm: npm install botlist.me.js
If using yarn: yarn add botlist.me.js
const BotlistMeClient = require('botlist.me.js');
const botlistme = new BotlistMeClient('Your botlist.me authorization token', { webhookPort: 3000, webhookAuth: 'password' });
botlistme.webhook.on('ready', hook => {
console.log(`Webhook running at http://${hook.hostname}:${hook.port}${hook.path}`);
});
botlistme.webhook.on('vote', vote => {
console.log(`User with ID ${vote.user} just voted!`);
});
Using Express
First you need to install express using one of the following commands depending on your package manager;
If using npm: npm install express
If using yarn: yarn add express
.
// Require express and body-parser
const express = require("express")
// Initialize express
const app = express()
// Define a port for the webserver to run on.
const PORT = 3000
// Tell express to use body-parser's JSON parsing
app.use(express.json())
app.post("/voted", (req, res) => {
console.log(req.body) // Logs what is posted to this endpoint. You can remove this line so that your console doesn't get spammed
// Below replace "WEBHOOKtokenHere" to the webhook "password" that you set
if (req.header('Authorization') != "WEBHOOKtokenHERE") {
return res.status("401").end(); // Return 401: Unauthorized
}
// Write some code that will do something for a user that votes
console.log(`${req.body.user} has voted for ${req.body.bot} on botlist.me`);
res.status(200).end() // Responds to the post request
})
// Start express on the defined port
app.listen(PORT, () => console.log(`🚀 Server running on port ${PORT}`))
Example implementation in Python
You can use botlist.py
python api wrapper made by DS_Stift007 to implement webhooks or you can create your own webserver using a module like Flask
if you wish.
Using botlist.py
First install the module using pip install git+https://github.com/Stift007/botlist.py.git
from botlistpy.webhook import Webhook
from typing import Union
from botlistpy.abc import ItemStruct
async def getvote(vote:Union[dict, ItemStruct]):
print(vote["user"]+" has voted!")
wh = Webhook(coroutine=getvote)
wh.run(80)