I'm new to discord.js. I'm trying to check if a message contains a link like "Hi, I'm from discord.gg/xxxxx and now I'll spam my link".
How can I check if the message contain the link?
To get the Message Link, click on the 3 dots to the far right of the message. You will see an option to Copy Link.
Scroll down to the Embeds section and click the + icon to create your hyperlink. In the Embeds description text area write your message in this format, prefix [ text ] ( link ) just like we did with the Carl Bot description.
Basically a link that takes the person directly to the direct messages with a certain user, similar to a server invitation link.
I am unsure if you want to check for discord invite links specifically, or if you want to check for all links. Either way, you can use message.content.includes
.
Example:
bot.on('message', (message) => { //whenever a message is sent
if (message.content.includes('discord.gg/'||'discordapp.com/invite/')) { //if it contains an invite link
message.delete() //delete the message
.then(message.channel.send('Link Deleted:\n**Invite links are not permitted on this server**'))
}
})
I find this is the best:
let regx = /^((?:https?:)?\/\/)?((?:www|m)\.)? ((?:discord\.gg|discordapp\.com))/g
let cdu = regx.test(message.content.toLowerCase().replace(/\s+/g, ''))
Tell me if it works!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With