【问题标题】:How can you make a mimic command using discord.js v12?如何使用 discord.js v12 制作模拟命令?
【发布时间】:2021-05-02 19:04:41
【问题描述】:

我想知道如何让我的机器人发送带有其他人的头像和昵称的消息。许多机器人都具有此功能,例如,对于您可以立即看到的建议日志以及谁想到了该建议,它可能非常有用。 我不确定我是否解释得足够好,所以我将在此处为您提供图像示例。

我找不到任何关于此的教程/文章,所以如果解释起来太复杂,链接到教程就足够了。

【问题讨论】:

    标签: discord discord.js


    【解决方案1】:

    他们使用webhooks,可以这样创建:

    const webhook = await channel.createWebhook('Some-username', {
        avatar: 'https://i.imgur.com/wSTFkRM.png',
    })
    

    因此,您需要设置用户名和头像来模仿目标。然后,要触发 webhook,您需要安装 node-fetch (npm i node-fetch),并且:

    const fetch = require('node-fetch');
    
    const webhookURL = webhook.url;
    await fetch(webhookURL, {
        headers: {'Content-Type': 'application/json' },
        method: 'POST',
        body: JSON.stringify({
            content: 'your message here'
        })
    });
    

    这将触发 webhook。然后,删除 webhook:

    await webhook.delete()
    

    这是 webhook 的基础知识,要了解更多信息,请尝试this video。希望对您有所帮助!

    【讨论】:

      猜你喜欢
      • 2021-01-01
      • 2021-02-18
      • 1970-01-01
      • 2021-03-26
      • 1970-01-01
      • 2021-01-18
      • 2021-04-14
      • 2021-04-19
      • 2021-04-18
      相关资源
      最近更新 更多