首页 文章

将DM消息转发给公会 Channels

提问于
浏览
0

我希望在我的机器人收到直接消息时将其发送到我的公会中的 Channels . 我该如何实现这一目标?

我知道我必须使用 if (message.channel.type == "dm") {} ,但是如何获取机器人收到的内容并将其发送到特定 Channels 中的特定服务器?

1 回答

  • 1

    如果您只想发送文本,只需发送其内容:

    client.on("message", msg => {
      if (msg.channel.type == "dm") mychannel.send(msg.content); //mychannel is your TextChannel object
    });
    

    如果你想做到这一点,你可以看到作者和类似的东西,你可以使用嵌入(请参阅如何构建和发送一个here) .

    如果你想使它与某人的消息几乎完全相同,你可以使用webhook:

    guild.fetchWebhooks().then(webhooks => {
      let myhook = webhooks.find("placeholder");
    
      client.on("message", msg => {
        if (msg.channel.type == "dm") myhook.send(msg.content, {
          username: msg.author.username,
          avatarURL: msg.author.avatarURL,
        });
      });
    });
    

    希望这有帮助,如果您有任何其他问题,请告诉我

相关问题