简体   繁体   English

如何制作 Discord 邀请过滤器?

[英]How I can make Discord Invite filter?

I want to make a working Discord Invite filter, which is configurable and you can advertise on channels added to exception list.我想做一个有效的 Discord 邀请过滤器,它是可配置的,您可以在添加到例外列表的频道上做广告。 I have created the code earlier, but it does not work properly.我之前已经创建了代码,但它不能正常工作。 Here is the code:这是代码:

if (message.content.includes("https://discord.gg/")) {
    if (!db.fetch(`${message.guild.id}.antiad`) ||
      db.fetch(`${message.guild.id}.antiad`) == "disabled" ||
      message.channel.id == db.fetch(`${message.guild.id}.exceptionChannels.${message.channel.id}`))
      return;
    try {
      message.delete();
      let embed = new Discord.RichEmbed()
        .setDescription(
          `<@${message.author.id}>, you cannot advertise here!`
        )
        .setColor("RED");
      message.channel.send(embed);
    } catch (err) {
      console.log(err);
    }
  }

I am not getting any error messages in my console, by the way.顺便说一句,我的控制台中没有收到任何错误消息。 Anyone knows how to help me with this?有人知道如何帮助我吗? Thanks for any help.谢谢你的帮助。

You could create a RegExp and test to see if the content contains an invite link:您可以创建一个RegExp并测试以查看内容是否包含邀请链接:

const inviteRegex = new RegExp(/(https?:\/\/)?(www\.)?(discord\.(gg|io|me|li)|discordapp\.com\/invite)\/.+[a-z]/g);
if (!inviteRegex.test(message.content) {
    message.delete({ reason: 'Advertising' });
    return message.reply('You can not advertise here!');
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM