【问题标题】:Discord Bot: How to exclude a certain channelsDiscord Bot:如何排除某些频道
【发布时间】:2020-11-28 01:28:56
【问题描述】:
client.on('messageDelete', function (message) {
  if (message.channel.type === 'text') {
    var log = client.channels.cache.get("44444444444444444")
    if (log != null) {
      client.channels.cache.get('4444444444444').send('**DELETED** ' + `${message.author}` + '\: ' + message.cleanContent + ' ')
    }
  }
})

这是我记录已删除消息的脚本。

如何排除某些渠道和/或某些用户,例如机器人?
我应该使用类似的东西:

if (message.channel.type === 'text') & channels... & users...

【问题讨论】:

  • 是的,应该可以。你会想做一些更像if( message.channel.type === "text" && channels && users) 的事情。试一试,如果您在运行它时遇到任何问题,请告诉我们。

标签: javascript node.js discord bots discord.js


【解决方案1】:

最简单的方法是将排除的频道和用户存储在某种数组中,并检查 message.author 或 message.channel 是否在其中一个数组中。您可以使用 User 的 author.bot 属性轻松检查消息的作者是否是机器人。

if (message.author.bot) return;
    channels.forEach(element => {
if (element == message.channel) return;
});
    users.forEach(element => {
if (element == message.author) return;
});

【讨论】:

    猜你喜欢
    • 2021-02-26
    • 2020-03-12
    • 2019-05-05
    • 1970-01-01
    • 2020-12-04
    • 2020-10-01
    • 2020-07-13
    • 2020-11-04
    • 2021-07-20
    相关资源
    最近更新 更多