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

161
Vistas
How to delete all messages that have URLs that are not www.youtube.com or www.twitter.com

I am new here, and recently I have been facing a big problem with Discord Scam Links in my Discord server, I tried that:

if(message.content.includes("discordscam.com")) {
   message.delete()
   }

But this is a very bad way to fight scams since it will only delete one specific URL and not other ones, I realized that I should use RegExp, but, unfortunately, I don't understand how.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Because contents may include multiple urls, you'll need to check each word. First filter words to just any urls. Then from there check if any of the urls aren't twitter or youtube.

First regex is for url /^(https?:\/\/)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()!@:%_\+.~#?&\/\/=]*)/

Next regex is for allowed urls (youtube|twitter).com

// split contents by word, check each word
function shouldDelete(contents){
   
    let urlFilter = contents.split(' ').map(word => {
        let t = word.match(/^(https?:\/\/)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()!@:%_\+.~#?&\/\/=]*)/)
        return t?.length > 0 ? t[0] : null
    }).filter(url=>{
        if(!url || /(youtube|twitter).com/g.test(url)) return
        else
          return url
    })
    if(urlFilter.length > 0){
        return `"${contents}" should delete`
    }else{
        return `"${contents}" shouldn't delete`
    }
}

let sampleContents=[
  'twitter.com',
  'youtube.com',
  'discordscam.com',
  'discordscam.com and youtube.com',
  'https://www.youtube.com/watch?time_continue=2&v=dQw4w9WgXcQ&feature=emb_logo'
]

sampleContents.forEach(item=>{
    console.log(shouldDelete(item))
})

about 4 years ago · Juan Pablo Isaza Denunciar

0

Hopefully this helps point you in the right direction!

I have a regular expression that is validating based on the string either having youtube or twitter, followed by .com and can not have any more periods afterwards.

const urlTest = str => 
  /^.*(youtube|twitter)\.com[^.]*$/.test(str);
  
console.log(`
  testing "youtube.com"
  good? ${urlTest("youtube.com")}
  
  testing "twitter.com"
  good? ${urlTest("twitter.com")}
  
  testing "youtube.com.net"
  good? ${urlTest("youtube.com.net")}
  
  testing "https://somesite.com/nothing"
  good? ${urlTest("https://somesite.com/nothing")}
  
  testing "https://youtube.com/somethingelse"
  good? ${urlTest("https://youtube.com/somethingelse")}
`);

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