Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

107
Vistas
Check if someone sent the message twice

On my server, we have a channel for just one word, "Oi".

If someone sends something other than the word "Oi", it gets deleted. But now I need a code that deletes the message if someone sends it twice in a row. They have to wait for someone else to send if they want to send.

This is my current code if you want to check it out for some reason:

if (message.channel.id === "ChannelIdWhichImNotGonnaTell") {
  if (message.content === "Oi") {
    let log = client.channels.cache.get("ChannelIdWhichImNotGonnaTell")
    log.send(`New Oi By ${message.author.tag}`)
  } else {
    message.delete()
  }
}
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

There's some several work around for this. But I found this is the efficient way to do that.

As you said 'They have to wait for someone else to send oi' then you should fetch the "old message" before "the new message" that sent. and try to get the User ID. Then compare it with the new message one.

Here is the Example code :

if (message.content === 'Oi') {

    message.channel.messages.fetch({limit: 2})
    .then(map => {
    let messages = Array.from(map.values());
    let msg = messages[1];
    if (msg.author.id === message.author.id){

        message.delete();
        // do something

    } else {

       let log = client.channels.cache.get("ChannelID")
       log.send(`New Oi By ${message.author.tag}`)

    }}).catch(error => console.log("Error fetching messages in channel"));

}

It will compare the "old messages" author UserID with the "new messages" author UserID. If it's match. Then it will be deleted.

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can fetch() the last two messages by using the limit option and the last() in the returned collection will be the second last message in the channel (the one before the last one triggered your code).

Then you can compare the author's IDs; if they are the same, you can delete the message:

if (message.channel.id === oiChannelID) {
  if (message.content === 'Oi') {
    // fetch the last two messages
    // this includes this one and the previous one too
    let lastMessages = await message.channel.messages.fetch({ limit: 2 });
    // this is the message sent before the one triggered this command
    let previousMessage = lastMessages.last();

    if (previousMessage.author.id === message.author.id) {
      console.log('No two Ois, mate');
      message.delete();
      // don't execute the rest of the code
      return;
    }

    let log = client.channels.cache.get(logChannelID);
    log.send(`New Oi By ${message.author.tag}`);
  } else {
    message.delete();
  }
}

enter image description here

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda