机器人正在删除所有消息

时间:2019-11-13 03:03:22

标签: javascript discord discord.js

我编写了此脚本,以删除特定频道中不是图像的所有消息,但该漫游器删除了所有文本消息和图像。

代码如下:

client.on("message", (message) => {
  let channel = client.channels.get(`642417479708049418`);
  if (message.author.bot) return;
  if (message.member.roles.some(r => ["DEAN!"].includes(r.name))) return;
  if (message.channel.id != channel.id) {
    return
  } else {
    if (message.embeds.length > 0) {
      return
    } else {
      message.channel.send(`${message.author} this channel is for images only`);
      message.delete();
    }
  }
});

1 个答案:

答案 0 :(得分:0)

您需要使用MessageAttachments:

client.on("message", (message) => {
  let channel = client.channels.get(`642417479708049418`);
  if (message.author.bot) return;
  if (message.member.roles.some(r => ["DEAN!"].includes(r.name))) return;
  if (message.channel.id != channel.id) {
    return
  } else {
    if (message.attachments.size > 0) {
      return
    } else {
      message.channel.send(`${message.author} this channel is for images only`);
      message.delete();
    }
  }
});