0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【discord.js】なぜ転送メッセージは荒らし対策BOTを貫通してしまうのか。

Last updated at Posted at 2025-04-05

お久しぶりです。りょうです。
今回はdiscordの転送メッセージが荒らし対策BOTを貫通してしまう原因について書きます。

転送メッセージ

別の場所から自分が送信できる場所にメッセージ(画像や動画含む)を転送して共有できるようにする機能です

image.png

貫通の原因

転送メッセージの中身です↓

<ref *1> Message {
  channelId: '1280866748920365121',
  guildId: '1280866748920365118',
  id: '1357897427893485628',
  createdTimestamp: 1743818375324,
  type: 0,
  system: false,
  content: '',
  author: User {
    id: '1095869643106828289',
    bot: false,
    system: false,
    flags: UserFlagsBitField { bitfield: 4194560 },
    username: 'ryo_001339',
    globalName: 'りょう',
    discriminator: '0',
    avatar: '03b6b8934fa4b517f8a2384dcb2123de',
    banner: undefined,
    accentColor: undefined,
    avatarDecoration: null,
    avatarDecorationData: null
  },
  pinned: false,
  tts: false,
  nonce: '1357897423111847936',
  embeds: [],
  components: [],
  attachments: Collection(0) [Map] {},
  stickers: Collection(0) [Map] {},
  position: 0,
  roleSubscriptionData: null,
  resolved: null,
  editedTimestamp: null,
  reactions: ReactionManager { message: [Circular *1] },
  mentions: MessageMentions {
    everyone: false,
    users: Collection(0) [Map] {},
    roles: Collection(0) [Map] {},
    _members: null,
    _channels: null,
    _parsedUsers: null,
    crosspostedChannels: Collection(0) [Map] {},
    repliedUser: null
  },
  webhookId: null,
  groupActivityApplication: null,
  applicationId: null,
  activity: null,
  flags: MessageFlagsBitField { bitfield: 16384 }, // MessageFlagsBitField.HasSnapshot
  reference: {
    channelId: '1280866748920365121',
    guildId: '1280866748920365118',
    messageId: '1357897357479510207',
    type: 1
  },
  interactionMetadata: null,
  interaction: null,
  poll: null,
  messageSnapshots: Collection(1) [Map] { // 転送メッセージの中身
    '1357897357479510207' => Message {
      channelId: '1280866748920365121',
      guildId: '1280866748920365118',
      id: '1357897357479510207',
      createdTimestamp: 1743818358536,
      type: 0,
      system: false,
      content: '',
      author: [User],
      pinned: false,
      tts: false,
      nonce: '1357897352794341376',
      embeds: [],
      components: [],
      attachments: Collection(0) [Map] {},
      stickers: Collection(0) [Map] {},
      position: null,
      roleSubscriptionData: null,
      resolved: null,
      editedTimestamp: null,
      reactions: [ReactionManager],
      mentions: [MessageMentions],
      webhookId: null,
      groupActivityApplication: null,
      applicationId: null,
      activity: null,
      flags: [MessageFlagsBitField],
      reference: null,
      interactionMetadata: null,
      interaction: null,
      poll: null,
      messageSnapshots: Collection(0) [Map] {},
      call: null
    }
  },
  call: null
}

荒らし対策のBOTの多くはmessage.contentに招待リンクなどが含まれていないかを確認するようになっています。
ですが、転送メッセージはmessageSnapshotsの部分にあるため、contentは''、つまり何も入っていないんです。だから見過ごされて貫通してしまいます。
(オプションで追加されたメッセージは普通にmessage.contentに入ります)

image.png

対策

if (message.messageSnapshots?.size) {
  console.log(message.messageSnapshots.first().content); // ここは適切な処理に変えて
}

これは一例ですが、messageSnapshotsが存在するかつ1件以上あるかを確認し、満たした場合に処理を行うようにすれば転送メッセージへの対応ができます。
message.messageSnapshots は Collection オブジェクトなので、.first()values().next().value を使って要素を取得できます

他にも一定時間内に同一ユーザーからのmessageCreateが◯件発生したら対処にすれば対策できます

まとめ

短いですが終わりです
これはもっとこうしたほうがいいんじゃないかなどの提案や意見、質問等あれば書いてもらえると助かります

Discordに湧く荒らしの情報や対策方法の共有をしている自鯖です(1100人いきました!)
よければ参加お願いします↓

twitter🐦️

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?