【问题标题】:Discord bot ignore all webhooks?Discord bot 忽略所有 webhook?
【发布时间】:2020-11-11 11:14:24
【问题描述】:

我有一个使用调平系统的不和谐机器人。它侦听message.author.id,记录最新消息,为用户提供 XP,在某些级别,用户被授予新角色。几个月来一直运行良好。

最近我向服务器添加了几个(准确地说是 10 个)网络挂钩,以使用户能够发送错误报告。 问题是我的机器人也在读取这些 webhook 消息,而 webhook 没有作者 ID,因此,每次 webhook 发布内容时,机器人都会崩溃。

我知道我们可以除了像 if (message.webhookID != 'X') return; 这样的某些 webhook 但这有点不方便,因为我将来可能会添加或删除 webhook。有没有办法让我的机器人忽略所有 webhook,就像它可以忽略其他机器人一样?

编辑 这就是我所做的,

client.on('message', (message) => {

//Check if its a webhook.
if (message.webhookID) {
  // block of code to be executed if the condition is true
} else {
  // block of code to be executed if the condition is false

  if (message.guild.id != '335008833267040256')return;{
....

【问题讨论】:

    标签: javascript discord.js


    【解决方案1】:

    是的,您可以使用 if (message.webhookID) return;,如果消息是从 any webhook 发送的,则应该返回。

    【讨论】:

    • 哦,我怎么没想到呢?这解决了我的问题,干杯伙伴!
    • 试图弄清楚如何在 python 中使用 COG 来做到这一点 ?
    猜你喜欢
    • 1970-01-01
    • 2020-01-09
    • 2021-09-20
    • 2020-08-17
    • 1970-01-01
    • 2021-04-21
    • 2021-02-15
    • 2019-01-12
    • 2021-06-25
    相关资源
    最近更新 更多