如何使DIscord.js机器人真正回复邮件? [英] How do I make a DIscord.js bot actually reply to a message?

查看:90
本文介绍了如何使DIscord.js机器人真正回复邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在制造一种Discord.js(V12)机器人,该机器人支持命令"say"的类型.(请注意,我是新手),但是当我使用此"say"时,命令,然后单击答复"在特定的消息中,它只是发送我写的消息,而根本不显示我在答复的原始消息.这是我用机器人写的内容

I've been making a Discord.js (V12) bot that supports the type of command "say" (please note I'm new to this), but when I use this "say" command and click "reply" in a specific message it just sends the message I've wrote, it doesn't show the original message I was replying at all. Here is what I wrote with the bot and here the result.

我的说法"命令代码很简单,因为我找不到实际的回复功能,所以我无法添加它(我必须删除内容以便更准确).

My "say" command code is simple because I couldn't find the actual reply function so I couldn't add it (I had to delete content so it's more accurate).

client.on('message', (message) => {
    if (message.content.startsWith('p:')) {
      //This line reads the content of the message, creates the variable "say" for it.
        var say = message.content;
      //This removes my message, so it can be replaced by bot's one.
        message.delete();
      //This line deletes the prefix from "say" and sends the rest of the message.
        message.channel.send(say.replace('p:', '')
    .catch(() => console.error('Failed to send - Can\'t send empty messages!'));
    }
});

我发现还有另一种回复方法.这两个:第一个是普通的,另一个是由Tupperhook(Webhook)创建的机器人Tupperbox.

I've found out that there is another way to make a reply. Here the two: The first one is the normal and the other is by a Tupperhook (Webhook) created by the bot Tupperbox.

有什么办法至少可以对Webhook的机器人回复版本吗?

Is there any way to make at least a version of the Webhook's reply for the bot?

在Webhook方法可以工作的情况下,我已经可以跳到一条消息了(在此示例中,原始消息正在触发特定的命令-将更改为跳到已回复的消息).嵌入,这是它的代码.

In the case that the Webhook method can work, I already have the way to jump to a message (in this example the original message is triggering a specific command - this would be changed to jump to the replied message) inside of an embed, and here's the code for it.

//These should be in the embed command.
//This line recognizes the servers the bot is in.
  var guild = message.guild
//This other line recognizes the channels of the servers.
  var channel = message.channel
//This one sends the word "Message" and includes a link to the message that triggered this command.
  `[Message](https://discordapp.com/channels/${guild.id}/${channel.id}/${message.id})`

是否可以使我的代码适应这些回复功能中的任何一个?我发誓自一个月以来一直在尝试这种方法.任何答案都非常感谢!

Is it possible to adapt my code to any of those reply functions? I swear I'm trying this since one month. Any answer is really appreciated!

推荐答案

在v12中无法执行此操作,但可以通过更具体的API请求进行操作

There's no way to do that in v12 but it's possible with an API request more specifically Create Message.

允许我们回复消息的字段为

And the field that allows us to reply to a message is message_reference

const fetch = require('node-fetch')
client.on("message", (message) => {
  if (message.author.bot) return;
  const url = `https://discord.com/api/v8/channels/${message.channel.id}/messages`;
  var payload = {
    content: "Hello, World!",
    tts: false,
    message_reference: {
      message_id: message.id
    }
  };
   fetch(url, {
    method: "POST",
    body: JSON.stringify(payload),
    headers: {
      Authorization: `${client.user?.bot ? "Bot " : ""}${client.token}`,
      'Accept': 'application/json',
      'Content-Type': 'application/json'
    },
  }).catch(() => { });
});

这篇关于如何使DIscord.js机器人真正回复邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆