You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何获取发送至服务器的Webhook详情?Discord BOT拦截功能实现求助

Discord机器人拦截Webhook消息问题及Webhook详情获取咨询

各位同事下午好。我正在为我的Discord服务器开发一款机器人,唯一功能是拦截通过Webhook接收的消息,但目前还没成功实现。运行代码时出现如下错误:

错误截图

以下是我当前的代码:

const {
  Client,
  GatewayIntentBits,
  Partials,
  Collection,
  WebhookClient,
} = require("discord.js");
// const { Webhook } = require("discord-webhook-node");
const config = require("./config");
const webhook = new WebhookClient([config.webhooks.bizDataMr]);
console.clear();

//webhook.fetchMessage()

const client = new Client({
  intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages],
  partials: [Partials.GUILD_MEMBER, Partials.USER],
});

client.on("ready", () => {
  console.log(`${client.user.tag} is alive!`);
});

client.on("messageCreate", async (msg) => {
  if (
    msg.author.id === "1169644794788716685" ||
    msg.author.id === "282859044593598464"
  )
    return;

  const destinyChannel = msg.guild.channels.cache.get("1169671299459731536");
  if (msg.channelId === "1169011873031659590") {
    console.log(msg);
    console.log(await webhook.fetchMessage(msg.id));
    destinyChannel.send(
      `New message in <#${msg.channelId}>, <@&1169442693756223508>`
    );
  }
});

client.setMaxListeners(0);

client.login(config.bot.token);
// .login(config.bot.token)
// .then(() => {
//   console.log(`${client.user.username} is active`);
// })
// .catch((err) => {
//   console.error(err);
// });

我知道代码较为杂乱,打算实现功能后再进行整理。

请问:

  • 我能否通过WebhookClient实现拦截Webhook消息的需求?或者该需求是否无法完成?
  • 如何获取发送至我的服务器的Webhook详情?

内容的提问来源于stack exchange,提问作者Saco04

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 10:01:08