【问题标题】:Top.gg vote webhook (discord.js)Top.gg 投票 webhook (discord.js)
【发布时间】:2021-07-17 19:39:45
【问题描述】:

我正在尝试制作一个 top.gg 投票 webhook,由于某种原因,当我对其进行投票时,它会返回“未定义”。这是我的代码:

const express = require('express');
const app = express();
const bodyParser = require('body-parser');

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

app.use(express.static('public'));

app.get('/', function(req, res){
    res.send(`This is not a website!`);
});

app.post('/dblwebhook', function(req, res) {
    if(req.headers.authorization !== 'top.gg auth') return console.log(`Invalid request!`);
    if(req.body.type === 'test'){
        console.log(req.vote); //gives back 'undefined'
    } else {
        console.log(req.vote); //gives back 'undefined'
    }

   res.send({code: 'success'});
});

有人看到我做错了吗?

【问题讨论】:

    标签: javascript node.js discord discord.js


    【解决方案1】:

    找到答案了,忘记添加@topgg/sdk 包中的webhook 中间件。它使它看起来像这样:

    const express = require('express');
    const app = express();
    const bodyParser = require('body-parser');
    const topgg = require('@topgg/sdk');
    
    const webhook = new topgg.Webhook('auth');
    
    app.use(bodyParser.json());
    app.use(bodyParser.urlencoded({ extended: true }));
    
    app.use(express.static('public'));
    
    app.get('/', function(req, res){
        res.send(`This is not a website!`);
    });
    
    app.post('/dblwebhook', webhook.middleware(), function(req, res) {
        if(req.headers.authorization !== 'top.gg auth') return console.log(`Invalid request!`);
        if(req.body.type === 'test'){
             console.log(req.vote);
        } else {
             console.log(req.vote);
        }
    
       res.send({code: 'success'});
    });
    

    【讨论】:

      猜你喜欢
      • 2022-01-10
      • 2022-08-02
      • 2021-05-07
      • 2020-12-04
      • 2019-04-03
      • 1970-01-01
      • 2012-10-29
      • 2012-07-14
      • 1970-01-01
      相关资源
      最近更新 更多