0

im pretty new to javascript and i tried to get and modify a script that delete link if its not in the list, i tried multiple modification for hours but none succeed, the bot delete all link. What have i missed ?

var channelID = ["974353308800139354","770229235788677161"]

//Credits: https://stackoverflow.com/questions/6707476/how-to-find-if-a-text-contains-url-string
const regexChecker = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gi.test(context.params.event.content)

if((!regexChecker)||(channelID.includes(message.channel.id))) return;

/* Delete Message */
await lib.discord.channels['@0.1.1'].messages.destroy({
  message_id:  context.params.event.id,
  channel_id: context.params.event.channel_id
});
/* Send the alert message */
return await lib.discord.channels['@0.1.1'].messages.create({
  channel_id: context.params.event.channel_id,
  content: `<@${context.params.event.author.id}> You cant post link here.`
}); 

2 Answers2

0
if((!regexChecker)||(channelID.includes(message.channel.id))) return;

This deletes links on all channel except channels which in your array.

if((!regexChecker)||(!channelID.includes(message.channel.id))) return;

This deletes links only in channels which in your array.

Neenhila
  • 187
  • 2
  • 9
  • hi, so i tried to put the good value in "var channelID", but the bot dont want to delete links anymore, have i done something wrong ? – arrbiter May 14 '22 at 09:18
  • What do you want actually? Can you share it more understandable. – Neenhila May 14 '22 at 16:52
  • ho sorry, i want this script to delete any links posted on my server exept for 2channels, but when i added "||(channelID.includes(message.channel.id)))", the script dont work anymore, it doesnt delete links for some reason. – arrbiter May 14 '22 at 18:19
0

you can use that:

var channelID = ["974353308800139354","770229235788677161"]

    const pub = [
      "discord.me",
      "dsc.gg",
      "discord.io",
      "discord.gg",
      "invite.me",
      "discordapp.com/invite",
      ".gg"
    ];
if (pub.some(word => message.content.includes(word))) {
if (message.channel.id.includes(channel)){return;}
          else{message.delete().catch(err => { })}
Sans
  • 13
  • 5