Could someone help me with this script?

barby1

Regular Member
Joined
Dec 25, 2015
Messages
230
Reaction score
33
I want add to the script this: if appear this: https://t.co/8KqUI change for https://hello.com/

Code:
const Discord = require('discord.js');
const client = new Discord.Client();

client.on('ready', () => {
  console.log(`Logged in as ${client.user.tag}!`);
});

client.on('message', msg => {
    if (msg.author.bot) return;

resend(msg);
function resend(msg){
    let words = ['#qwerty', 'asdf'];
    let author = msg.author.id;
    let content = msg.content;
    let chan = msg.channel;
    let wordsStr = words.join('|');
    let regex = new RegExp('('+wordsStr+')', 'g');
    if(msg.content.match(regex)){
        content = content.replace(regex, '' );
        msg.delete().then(() => {
            chan.send( new Discord.RichEmbed()
                            .setDescription(content)
                            .setColor(0x4cff00)
            );
        }).catch((e) => {console.error(e);});
    }
}
});
//client.login('token');
client.login('NDQ0MjY5OTgklVz107oc7oEEcgM');
 
You can add these definitions inside the resend function:

Code:
var linkRegex  = new RegExp( "https:\/\/t\.co\/[a-zA-Z0-9]{3,6}", "g" );
var linkTarget = "https://hello.com/";
msg.content    = msg.content.replace( regexLink, target );

You can test it out here: https://jsfiddle.net/rar6naat/
 
Back
Top