【问题标题】:How to send dm as bot after voted top.gg discord.js?投票 top.gg discord.js 后如何将 dm 作为机器人发送?
【发布时间】:2022-01-10 20:35:30
【问题描述】:
const Discord = require(discord.js);
const client = new Discord.Client();
const Topgg = require ("@top-gg/sdk");

所以我不知道下一个代码 很抱歉我学javascript太早了

我在这里使用 discord.js V12

【问题讨论】:

    标签: javascript discord discord.js vote dm


    【解决方案1】:

    你还没有正确地需要 Discord。应该是require("discord.js");,否则你会尝试要求一个不存在的变量。

    滚动浏览 Top.gg API Docs 时,您似乎可以使用 webhook 类来获取用户投票的时间。

    const Discord = require("discord.js");
    const Client = new Discord.Client();
    // top.gg example
    const Topgg = require("@top-gg/sdk");
    // Webhook options can be found here if you wish to include them, currently the only one is an error callback: https://topgg.js.org/interfaces/webhookoptions
    // You'll have to set up a webhook on top.gg in your bot's settings
    const TopWebhook = new Topgg.Webhook("authorization");
    const express = require("express");
    const app = express();
    app.listen(process.env.PORT || 8080);
    
    // This example assumes you're using express
    app.post("/webhook", async TopWebhook.listener(vote) => {
        let user = vote.user; // the User ID
        // get the user from their user id, then send a DM
    });
    

    希望这有助于注意这是未经测试的,因此可能需要进行一些调整,但一定要阅读文档。

    【讨论】:

    • 所以我只需要写在 app.post 而不是 client.on
    • 当然,您仍然需要登录,但是 Top.gg 点赞监听器与您创建的 Discord 客户端完全无关,因此您可以监听的任何事件都不会真正产生影响。
    • 好的,非常感谢
    猜你喜欢
    • 2021-07-17
    • 2020-09-14
    • 2021-05-07
    • 2021-03-03
    • 1970-01-01
    • 2020-04-16
    • 1970-01-01
    • 2021-06-13
    • 2019-01-07
    相关资源
    最近更新 更多