'Discord Bot Auto Deletes Links In certain Channels
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.`
});
Solution 1:[1]
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.
Solution 2:[2]
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 => { })}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Neenhila |
| Solution 2 | Sans |
