A Discordjs Chat Filter










0















I'm making a discord.js bot and I was curious how to add a chat filter to it. As in a user says f*** and it will auto-delete.










share|improve this question






















  • See this answer.

    – Obsidian Age
    Oct 29 '18 at 22:24







  • 1





    Possible duplicate of "bad words" filter

    – Wesam
    Oct 29 '18 at 22:27






  • 1





    npmjs.com/package/bad-words

    – Frustrated programmer
    Oct 29 '18 at 23:17















0















I'm making a discord.js bot and I was curious how to add a chat filter to it. As in a user says f*** and it will auto-delete.










share|improve this question






















  • See this answer.

    – Obsidian Age
    Oct 29 '18 at 22:24







  • 1





    Possible duplicate of "bad words" filter

    – Wesam
    Oct 29 '18 at 22:27






  • 1





    npmjs.com/package/bad-words

    – Frustrated programmer
    Oct 29 '18 at 23:17













0












0








0








I'm making a discord.js bot and I was curious how to add a chat filter to it. As in a user says f*** and it will auto-delete.










share|improve this question














I'm making a discord.js bot and I was curious how to add a chat filter to it. As in a user says f*** and it will auto-delete.







json discord discord.js






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Oct 29 '18 at 22:21









pausepause

82




82












  • See this answer.

    – Obsidian Age
    Oct 29 '18 at 22:24







  • 1





    Possible duplicate of "bad words" filter

    – Wesam
    Oct 29 '18 at 22:27






  • 1





    npmjs.com/package/bad-words

    – Frustrated programmer
    Oct 29 '18 at 23:17

















  • See this answer.

    – Obsidian Age
    Oct 29 '18 at 22:24







  • 1





    Possible duplicate of "bad words" filter

    – Wesam
    Oct 29 '18 at 22:27






  • 1





    npmjs.com/package/bad-words

    – Frustrated programmer
    Oct 29 '18 at 23:17
















See this answer.

– Obsidian Age
Oct 29 '18 at 22:24






See this answer.

– Obsidian Age
Oct 29 '18 at 22:24





1




1





Possible duplicate of "bad words" filter

– Wesam
Oct 29 '18 at 22:27





Possible duplicate of "bad words" filter

– Wesam
Oct 29 '18 at 22:27




1




1





npmjs.com/package/bad-words

– Frustrated programmer
Oct 29 '18 at 23:17





npmjs.com/package/bad-words

– Frustrated programmer
Oct 29 '18 at 23:17












2 Answers
2






active

oldest

votes


















0














You can do this with an array of words,



var profanities = ["test1", "test2", "..."];


then in your bot.on message handler, or how you use to handle messages,



bot.on('message', async message => 
let msg = message.content.toLowerCase();
let Admin = message.guild.roles.find('name', "Admin"); // Change this to meet what you want
let General = message.guild.channels.find(`name`, "general"); // All text channels are lowecase. Change this to meet what you want
for (x = 0; x < profanities.length; x++) message.channel.id === General.id) return; // if you changed the name of the variables above, change these too.
if (msg.includes(profanities[x]))
await message.reply("You cannot say that here!")
message.delete()
// Your code here
return;


);


EDIT:
This is very basic, it won't look for substitute letters such as $, @ or numbers/spaces unless you code those directly in, which you can have a list of words then have a console log every word with substitute letters.






share|improve this answer

























  • Thanks! One more question, is there any way to make it to where Administrators bypass that? Or is there a way too make it ignore a certain channel?

    – pause
    Nov 12 '18 at 22:55











  • Yes, you can check if the sender has a certain role with this code, add it right under "let msg = ..." let role = message.guild.roles.find('name', "Case sensitive role name") message.member.roles.has(role.id), for your convience, I've updated the post

    – Steven Webster
    Nov 15 '18 at 16:45











  • I also forgot to say, you can check the channel as well! Both have been implemented in the code above, the 2 new variables are what you change. If you change the names of them make sure to do so in the new if statement too

    – Steven Webster
    Nov 15 '18 at 17:28












  • Thanks so much!

    – pause
    Nov 15 '18 at 21:07


















-1














client.on('message', message => 
message.delete(message.content.replace(/asshole/gi))
.catch(console.error);
);


This is just a example you can make it, with a text array too.






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53054737%2fa-discordjs-chat-filter%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    You can do this with an array of words,



    var profanities = ["test1", "test2", "..."];


    then in your bot.on message handler, or how you use to handle messages,



    bot.on('message', async message => 
    let msg = message.content.toLowerCase();
    let Admin = message.guild.roles.find('name', "Admin"); // Change this to meet what you want
    let General = message.guild.channels.find(`name`, "general"); // All text channels are lowecase. Change this to meet what you want
    for (x = 0; x < profanities.length; x++) message.channel.id === General.id) return; // if you changed the name of the variables above, change these too.
    if (msg.includes(profanities[x]))
    await message.reply("You cannot say that here!")
    message.delete()
    // Your code here
    return;


    );


    EDIT:
    This is very basic, it won't look for substitute letters such as $, @ or numbers/spaces unless you code those directly in, which you can have a list of words then have a console log every word with substitute letters.






    share|improve this answer

























    • Thanks! One more question, is there any way to make it to where Administrators bypass that? Or is there a way too make it ignore a certain channel?

      – pause
      Nov 12 '18 at 22:55











    • Yes, you can check if the sender has a certain role with this code, add it right under "let msg = ..." let role = message.guild.roles.find('name', "Case sensitive role name") message.member.roles.has(role.id), for your convience, I've updated the post

      – Steven Webster
      Nov 15 '18 at 16:45











    • I also forgot to say, you can check the channel as well! Both have been implemented in the code above, the 2 new variables are what you change. If you change the names of them make sure to do so in the new if statement too

      – Steven Webster
      Nov 15 '18 at 17:28












    • Thanks so much!

      – pause
      Nov 15 '18 at 21:07















    0














    You can do this with an array of words,



    var profanities = ["test1", "test2", "..."];


    then in your bot.on message handler, or how you use to handle messages,



    bot.on('message', async message => 
    let msg = message.content.toLowerCase();
    let Admin = message.guild.roles.find('name', "Admin"); // Change this to meet what you want
    let General = message.guild.channels.find(`name`, "general"); // All text channels are lowecase. Change this to meet what you want
    for (x = 0; x < profanities.length; x++) message.channel.id === General.id) return; // if you changed the name of the variables above, change these too.
    if (msg.includes(profanities[x]))
    await message.reply("You cannot say that here!")
    message.delete()
    // Your code here
    return;


    );


    EDIT:
    This is very basic, it won't look for substitute letters such as $, @ or numbers/spaces unless you code those directly in, which you can have a list of words then have a console log every word with substitute letters.






    share|improve this answer

























    • Thanks! One more question, is there any way to make it to where Administrators bypass that? Or is there a way too make it ignore a certain channel?

      – pause
      Nov 12 '18 at 22:55











    • Yes, you can check if the sender has a certain role with this code, add it right under "let msg = ..." let role = message.guild.roles.find('name', "Case sensitive role name") message.member.roles.has(role.id), for your convience, I've updated the post

      – Steven Webster
      Nov 15 '18 at 16:45











    • I also forgot to say, you can check the channel as well! Both have been implemented in the code above, the 2 new variables are what you change. If you change the names of them make sure to do so in the new if statement too

      – Steven Webster
      Nov 15 '18 at 17:28












    • Thanks so much!

      – pause
      Nov 15 '18 at 21:07













    0












    0








    0







    You can do this with an array of words,



    var profanities = ["test1", "test2", "..."];


    then in your bot.on message handler, or how you use to handle messages,



    bot.on('message', async message => 
    let msg = message.content.toLowerCase();
    let Admin = message.guild.roles.find('name', "Admin"); // Change this to meet what you want
    let General = message.guild.channels.find(`name`, "general"); // All text channels are lowecase. Change this to meet what you want
    for (x = 0; x < profanities.length; x++) message.channel.id === General.id) return; // if you changed the name of the variables above, change these too.
    if (msg.includes(profanities[x]))
    await message.reply("You cannot say that here!")
    message.delete()
    // Your code here
    return;


    );


    EDIT:
    This is very basic, it won't look for substitute letters such as $, @ or numbers/spaces unless you code those directly in, which you can have a list of words then have a console log every word with substitute letters.






    share|improve this answer















    You can do this with an array of words,



    var profanities = ["test1", "test2", "..."];


    then in your bot.on message handler, or how you use to handle messages,



    bot.on('message', async message => 
    let msg = message.content.toLowerCase();
    let Admin = message.guild.roles.find('name', "Admin"); // Change this to meet what you want
    let General = message.guild.channels.find(`name`, "general"); // All text channels are lowecase. Change this to meet what you want
    for (x = 0; x < profanities.length; x++) message.channel.id === General.id) return; // if you changed the name of the variables above, change these too.
    if (msg.includes(profanities[x]))
    await message.reply("You cannot say that here!")
    message.delete()
    // Your code here
    return;


    );


    EDIT:
    This is very basic, it won't look for substitute letters such as $, @ or numbers/spaces unless you code those directly in, which you can have a list of words then have a console log every word with substitute letters.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 15 '18 at 17:26

























    answered Nov 2 '18 at 1:37









    Steven WebsterSteven Webster

    467




    467












    • Thanks! One more question, is there any way to make it to where Administrators bypass that? Or is there a way too make it ignore a certain channel?

      – pause
      Nov 12 '18 at 22:55











    • Yes, you can check if the sender has a certain role with this code, add it right under "let msg = ..." let role = message.guild.roles.find('name', "Case sensitive role name") message.member.roles.has(role.id), for your convience, I've updated the post

      – Steven Webster
      Nov 15 '18 at 16:45











    • I also forgot to say, you can check the channel as well! Both have been implemented in the code above, the 2 new variables are what you change. If you change the names of them make sure to do so in the new if statement too

      – Steven Webster
      Nov 15 '18 at 17:28












    • Thanks so much!

      – pause
      Nov 15 '18 at 21:07

















    • Thanks! One more question, is there any way to make it to where Administrators bypass that? Or is there a way too make it ignore a certain channel?

      – pause
      Nov 12 '18 at 22:55











    • Yes, you can check if the sender has a certain role with this code, add it right under "let msg = ..." let role = message.guild.roles.find('name', "Case sensitive role name") message.member.roles.has(role.id), for your convience, I've updated the post

      – Steven Webster
      Nov 15 '18 at 16:45











    • I also forgot to say, you can check the channel as well! Both have been implemented in the code above, the 2 new variables are what you change. If you change the names of them make sure to do so in the new if statement too

      – Steven Webster
      Nov 15 '18 at 17:28












    • Thanks so much!

      – pause
      Nov 15 '18 at 21:07
















    Thanks! One more question, is there any way to make it to where Administrators bypass that? Or is there a way too make it ignore a certain channel?

    – pause
    Nov 12 '18 at 22:55





    Thanks! One more question, is there any way to make it to where Administrators bypass that? Or is there a way too make it ignore a certain channel?

    – pause
    Nov 12 '18 at 22:55













    Yes, you can check if the sender has a certain role with this code, add it right under "let msg = ..." let role = message.guild.roles.find('name', "Case sensitive role name") message.member.roles.has(role.id), for your convience, I've updated the post

    – Steven Webster
    Nov 15 '18 at 16:45





    Yes, you can check if the sender has a certain role with this code, add it right under "let msg = ..." let role = message.guild.roles.find('name', "Case sensitive role name") message.member.roles.has(role.id), for your convience, I've updated the post

    – Steven Webster
    Nov 15 '18 at 16:45













    I also forgot to say, you can check the channel as well! Both have been implemented in the code above, the 2 new variables are what you change. If you change the names of them make sure to do so in the new if statement too

    – Steven Webster
    Nov 15 '18 at 17:28






    I also forgot to say, you can check the channel as well! Both have been implemented in the code above, the 2 new variables are what you change. If you change the names of them make sure to do so in the new if statement too

    – Steven Webster
    Nov 15 '18 at 17:28














    Thanks so much!

    – pause
    Nov 15 '18 at 21:07





    Thanks so much!

    – pause
    Nov 15 '18 at 21:07













    -1














    client.on('message', message => 
    message.delete(message.content.replace(/asshole/gi))
    .catch(console.error);
    );


    This is just a example you can make it, with a text array too.






    share|improve this answer





























      -1














      client.on('message', message => 
      message.delete(message.content.replace(/asshole/gi))
      .catch(console.error);
      );


      This is just a example you can make it, with a text array too.






      share|improve this answer



























        -1












        -1








        -1







        client.on('message', message => 
        message.delete(message.content.replace(/asshole/gi))
        .catch(console.error);
        );


        This is just a example you can make it, with a text array too.






        share|improve this answer















        client.on('message', message => 
        message.delete(message.content.replace(/asshole/gi))
        .catch(console.error);
        );


        This is just a example you can make it, with a text array too.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Oct 29 '18 at 23:53









        Nisse Engström

        4,16292135




        4,16292135










        answered Oct 29 '18 at 23:36









        Esdese EsdeathEsdese Esdeath

        35




        35



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53054737%2fa-discordjs-chat-filter%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Top Tejano songwriter Luis Silva dead of heart attack at 64

            ReactJS Fetched API data displays live - need Data displayed static

            政党