Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
203 views
in Technique[技术] by (71.8m points)

javascript - How to use top,gg vote webhook?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Using top,gg webhooks is quite simple you need to make an simple web server with express which uses the top.gg/sdk as a middleware and attach the middleware to the server and then go to https://top.gg/botid/edit then into webhooks scroll down and set the url with the path assuming u have an ip x set the url as x/dblwebhook and set an password of your choice make a new file in your bot folder and put this code in

const init = async() => {
console.log('[EXPRESS] STARTING SERVER')
const express = require('express')
const app = express()
const Topgg = require('@top-gg/sdk')
const webhook = new Topgg.Webhook('password') // add your top.gg webhook authorization (not bot token)

app.post('/dblwebhook', webhook.middleware(), (req, res) => {
  // req.vote is your vote object e.g
  console.log(req.vote)
}) // attach the middleware

app.listen(25569, () => console.log('SERVER READY')
}
module.exports.init = init

then in your main bot file require it on the the top and call the init function like so

const {init} = require('./path-to-server-file')
init()

What's happening here is top.gg makes a post request to the url u specified with the details of the vote


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...