Granting a role from a custom command












0















I would like to make a custom command for my Discord server, where a user may authenticate using their username and password to obtain a special role. This username and password come from my own application and I would like to have people obtain a "Registered" role when they properly authenticate with the site.



I know that I will need a bot for the server - that's pretty much a no-brainer. But, how do I add a custom command so that people can send in their credentials to allow this? I may also use a temporary hash to avoid logging credentials - but, for now this is just theoretical anyway.



I am using the Discord.js package from NPM, per-se the official API client.










share|improve this question





























    0















    I would like to make a custom command for my Discord server, where a user may authenticate using their username and password to obtain a special role. This username and password come from my own application and I would like to have people obtain a "Registered" role when they properly authenticate with the site.



    I know that I will need a bot for the server - that's pretty much a no-brainer. But, how do I add a custom command so that people can send in their credentials to allow this? I may also use a temporary hash to avoid logging credentials - but, for now this is just theoretical anyway.



    I am using the Discord.js package from NPM, per-se the official API client.










    share|improve this question



























      0












      0








      0








      I would like to make a custom command for my Discord server, where a user may authenticate using their username and password to obtain a special role. This username and password come from my own application and I would like to have people obtain a "Registered" role when they properly authenticate with the site.



      I know that I will need a bot for the server - that's pretty much a no-brainer. But, how do I add a custom command so that people can send in their credentials to allow this? I may also use a temporary hash to avoid logging credentials - but, for now this is just theoretical anyway.



      I am using the Discord.js package from NPM, per-se the official API client.










      share|improve this question
















      I would like to make a custom command for my Discord server, where a user may authenticate using their username and password to obtain a special role. This username and password come from my own application and I would like to have people obtain a "Registered" role when they properly authenticate with the site.



      I know that I will need a bot for the server - that's pretty much a no-brainer. But, how do I add a custom command so that people can send in their credentials to allow this? I may also use a temporary hash to avoid logging credentials - but, for now this is just theoretical anyway.



      I am using the Discord.js package from NPM, per-se the official API client.







      node.js discord discord.js






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 25 '18 at 13:07









      Federico Grandi

      3,11321229




      3,11321229










      asked Nov 25 '18 at 7:20









      Ingwie PhoenixIngwie Phoenix

      8311721




      8311721
























          1 Answer
          1






          active

          oldest

          votes


















          1














          The basic structure for a command is: when you receive a message, check if it's a command and behave accordingly. You should write it like this:



          client.on('message' , msg => {
          // example: the command is "-test"

          let args = msg.content.split(' '),
          command = args.shift();
          if (command == "-test") {
          ...
          }
          });


          Please note that this is a very basic example and that there are more efficient ways to do that (it all depends on what you want to build and how you're going to do that).

          To add a role to a member you can use GuildMember.addRole(), here's an example:



          let {member} = msg;
          if (!member) return msg.reply("You're not in a guild.");
          member.addRole('role id here')
          .then(() => msg.reply("Role added."))
          .catch(console.error);


          Note: If you plan to add a lot of different commands, you may like the discord.js-commando library: it's a framework built to make command management easier.



          This is a quick approach to every part, let me know if you need more info about one aspect.






          share|improve this answer
























          • Thank you! Yes, I'd like to know if, and where messages like that are logged?

            – Ingwie Phoenix
            Nov 25 '18 at 17:29











          • Messages are not logged, so once you delete the message it's gone. If you have to write passwords make sure that the channel where they're sent it's visible only by that user (other users could log them with other scripts). Direct messages would be the perfect thing, because you're sure that they're seen only by the bot and the user. Keep in mind that Discord can read those messages if someone reports an issue to the Trust & Safety team

            – Federico Grandi
            Nov 25 '18 at 17:40











          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%2f53465466%2fgranting-a-role-from-a-custom-command%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          The basic structure for a command is: when you receive a message, check if it's a command and behave accordingly. You should write it like this:



          client.on('message' , msg => {
          // example: the command is "-test"

          let args = msg.content.split(' '),
          command = args.shift();
          if (command == "-test") {
          ...
          }
          });


          Please note that this is a very basic example and that there are more efficient ways to do that (it all depends on what you want to build and how you're going to do that).

          To add a role to a member you can use GuildMember.addRole(), here's an example:



          let {member} = msg;
          if (!member) return msg.reply("You're not in a guild.");
          member.addRole('role id here')
          .then(() => msg.reply("Role added."))
          .catch(console.error);


          Note: If you plan to add a lot of different commands, you may like the discord.js-commando library: it's a framework built to make command management easier.



          This is a quick approach to every part, let me know if you need more info about one aspect.






          share|improve this answer
























          • Thank you! Yes, I'd like to know if, and where messages like that are logged?

            – Ingwie Phoenix
            Nov 25 '18 at 17:29











          • Messages are not logged, so once you delete the message it's gone. If you have to write passwords make sure that the channel where they're sent it's visible only by that user (other users could log them with other scripts). Direct messages would be the perfect thing, because you're sure that they're seen only by the bot and the user. Keep in mind that Discord can read those messages if someone reports an issue to the Trust & Safety team

            – Federico Grandi
            Nov 25 '18 at 17:40
















          1














          The basic structure for a command is: when you receive a message, check if it's a command and behave accordingly. You should write it like this:



          client.on('message' , msg => {
          // example: the command is "-test"

          let args = msg.content.split(' '),
          command = args.shift();
          if (command == "-test") {
          ...
          }
          });


          Please note that this is a very basic example and that there are more efficient ways to do that (it all depends on what you want to build and how you're going to do that).

          To add a role to a member you can use GuildMember.addRole(), here's an example:



          let {member} = msg;
          if (!member) return msg.reply("You're not in a guild.");
          member.addRole('role id here')
          .then(() => msg.reply("Role added."))
          .catch(console.error);


          Note: If you plan to add a lot of different commands, you may like the discord.js-commando library: it's a framework built to make command management easier.



          This is a quick approach to every part, let me know if you need more info about one aspect.






          share|improve this answer
























          • Thank you! Yes, I'd like to know if, and where messages like that are logged?

            – Ingwie Phoenix
            Nov 25 '18 at 17:29











          • Messages are not logged, so once you delete the message it's gone. If you have to write passwords make sure that the channel where they're sent it's visible only by that user (other users could log them with other scripts). Direct messages would be the perfect thing, because you're sure that they're seen only by the bot and the user. Keep in mind that Discord can read those messages if someone reports an issue to the Trust & Safety team

            – Federico Grandi
            Nov 25 '18 at 17:40














          1












          1








          1







          The basic structure for a command is: when you receive a message, check if it's a command and behave accordingly. You should write it like this:



          client.on('message' , msg => {
          // example: the command is "-test"

          let args = msg.content.split(' '),
          command = args.shift();
          if (command == "-test") {
          ...
          }
          });


          Please note that this is a very basic example and that there are more efficient ways to do that (it all depends on what you want to build and how you're going to do that).

          To add a role to a member you can use GuildMember.addRole(), here's an example:



          let {member} = msg;
          if (!member) return msg.reply("You're not in a guild.");
          member.addRole('role id here')
          .then(() => msg.reply("Role added."))
          .catch(console.error);


          Note: If you plan to add a lot of different commands, you may like the discord.js-commando library: it's a framework built to make command management easier.



          This is a quick approach to every part, let me know if you need more info about one aspect.






          share|improve this answer













          The basic structure for a command is: when you receive a message, check if it's a command and behave accordingly. You should write it like this:



          client.on('message' , msg => {
          // example: the command is "-test"

          let args = msg.content.split(' '),
          command = args.shift();
          if (command == "-test") {
          ...
          }
          });


          Please note that this is a very basic example and that there are more efficient ways to do that (it all depends on what you want to build and how you're going to do that).

          To add a role to a member you can use GuildMember.addRole(), here's an example:



          let {member} = msg;
          if (!member) return msg.reply("You're not in a guild.");
          member.addRole('role id here')
          .then(() => msg.reply("Role added."))
          .catch(console.error);


          Note: If you plan to add a lot of different commands, you may like the discord.js-commando library: it's a framework built to make command management easier.



          This is a quick approach to every part, let me know if you need more info about one aspect.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 25 '18 at 13:06









          Federico GrandiFederico Grandi

          3,11321229




          3,11321229













          • Thank you! Yes, I'd like to know if, and where messages like that are logged?

            – Ingwie Phoenix
            Nov 25 '18 at 17:29











          • Messages are not logged, so once you delete the message it's gone. If you have to write passwords make sure that the channel where they're sent it's visible only by that user (other users could log them with other scripts). Direct messages would be the perfect thing, because you're sure that they're seen only by the bot and the user. Keep in mind that Discord can read those messages if someone reports an issue to the Trust & Safety team

            – Federico Grandi
            Nov 25 '18 at 17:40



















          • Thank you! Yes, I'd like to know if, and where messages like that are logged?

            – Ingwie Phoenix
            Nov 25 '18 at 17:29











          • Messages are not logged, so once you delete the message it's gone. If you have to write passwords make sure that the channel where they're sent it's visible only by that user (other users could log them with other scripts). Direct messages would be the perfect thing, because you're sure that they're seen only by the bot and the user. Keep in mind that Discord can read those messages if someone reports an issue to the Trust & Safety team

            – Federico Grandi
            Nov 25 '18 at 17:40

















          Thank you! Yes, I'd like to know if, and where messages like that are logged?

          – Ingwie Phoenix
          Nov 25 '18 at 17:29





          Thank you! Yes, I'd like to know if, and where messages like that are logged?

          – Ingwie Phoenix
          Nov 25 '18 at 17:29













          Messages are not logged, so once you delete the message it's gone. If you have to write passwords make sure that the channel where they're sent it's visible only by that user (other users could log them with other scripts). Direct messages would be the perfect thing, because you're sure that they're seen only by the bot and the user. Keep in mind that Discord can read those messages if someone reports an issue to the Trust & Safety team

          – Federico Grandi
          Nov 25 '18 at 17:40





          Messages are not logged, so once you delete the message it's gone. If you have to write passwords make sure that the channel where they're sent it's visible only by that user (other users could log them with other scripts). Direct messages would be the perfect thing, because you're sure that they're seen only by the bot and the user. Keep in mind that Discord can read those messages if someone reports an issue to the Trust & Safety team

          – Federico Grandi
          Nov 25 '18 at 17:40




















          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%2f53465466%2fgranting-a-role-from-a-custom-command%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

          404 Error Contact Form 7 ajax form submitting

          How to know if a Active Directory user can login interactively

          TypeError: fit_transform() missing 1 required positional argument: 'X'