Firstly, I’m a total noob to node.js and coding but have been teaching myself so apologies if this is just totally stupid/simple.
The intention is, someone posts a twitter link, the bot takes the message content, replaces twitter.com/x.com with “fxtwitter.com”, extracts the corrected URL and posts it in the channel, replying to the user.
I’ve managed to get this working fine by having the bot send content: twitterReplace
but obviously that quotes the whole message, I only want the URL.
So far I have this. I hope you can see what I’m trying to do here. I’m not even sure if let twitterReplaced = twitterReplace
is actually needed.
Bear with me…..
client.on("messageCreate", async (message) => {
const twitterTest = new RegExp(/b(httpsb://(x.com/|twitter.com/))(.*/status)/gm);
if (message.author.bot) return;
if (
twitterTest.test(message.content)
) {
let twitterReplace = message.content.replace(
/b(httpsb://(x.com|twitter.com))/gm,
"https://fxtwitter.com"
);
let twitterReplaced = twitterReplace
let twitterCut = new RegExp(/gb(httpsb://(fxtwitter.com)).+?(?=?)/gm)
let twitterFixed = twitterCut.match(twitterReplaced)
message.reply({content: twitterFixed, allowedMentions: {repliedUser: false}});
}
});
However the above gives an error that an empty message can’t be sent.
Any help is greatly appreciated.