FluGhost

Code avatar

Dec 14th, 2019
376
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const { Discord, MessageEmbed, Client } = require("discord.js");
  2. const client = new Client();
  3. const json = require("./file.json");
  4.  
  5. client.on("message", msg => {
  6.   const args = msg.content.split(/ + /g);
  7.   const cmd = args.shift().toLowerCase();
  8.  
  9. /* obtenir un utilisteur depuis une mention */
  10.     function getUserFromMention(mention) {
  11.       if (!mention) return;
  12.  
  13.       if (mention.startsWith("<@") && mention.endsWith(">")) {
  14.         mention = mention.slice(2, -1);
  15.  
  16.         if (mention.startsWith(json.prefix)) {
  17.           mention = mention.slice(1);
  18.         }
  19.  
  20.         return client.users.get(mention);
  21.       }
  22.     }
  23.  
  24.     /* avatar */
  25.     const avatarMeEmbed = new MessageEmbed()
  26.       .setTitle("This is your avatar !")
  27.       .setURL(`${msg.author.displayAvatarURL()}`)
  28.       .setDescription(
  29.         "Click on the title text to open this image on your browser. So you can download it."
  30.       )
  31.       .setImage(msg.author.displayAvatarURL())
  32.       .setColor(json.colorEmbed)
  33.       .setFooter(
  34.         "Bot created by : FluGhost#7007",
  35.         "https://image.noelshack.com/fichiers/2019/50/5/1576262895-flughostlogo.png"
  36.       );
  37.  
  38.     /* donnons à l'utilisateur son avatar */
  39.     if (cmd === json.prefix + "avatar" && !args[0]) {
  40.       msg.channel.send(avatarMeEmbed);
  41.       /* donnons à l'utisateur l'avatar de son tag */
  42.     } else if (
  43.       cmd === "avatar" &&
  44.       args[0].startsWith("<@") &&
  45.       args[0].endsWith(">")
  46.     ) {
  47.       /* si l'utilisateur n'a pas mis de bon arguments alors le rappeler à l'ordre */
  48.       const user = getUserFromMention(args[0]);
  49.       if (!user) {
  50.         msg.reply(
  51.           `Sorry, is you want to have an avatar of a user, tag it. Else, don't write arguments after the command.\n If you have questions, this commands can help you : \`${json.prefix}help\``
  52.        );
  53.        console.log(`${msg.author.name} hasn't writted the true arguments.`);
  54.       } else {
  55.         const avatarAutherEmbed = new MessageEmbed()
  56.           .setTitle(`This is the avatar of ${user} !`)
  57.           .setURL(`${user.displayAvatarURL()}`)
  58.           .setDescription(
  59.             "Click on the title text to open this image on your browser. So you can download it."
  60.           )
  61.           .setImage(user.displayAvatarURL())
  62.           .setColor(json.colorEmbed)
  63.           .setFooter(
  64.             "Bot created by : FluGhost#7007",
  65.             "https://image.noelshack.com/fichiers/2019/50/5/1576262895-flughostlogo.png"
  66.           );
  67.  
  68.         msg.channel.send(avatarAutherEmbed);
  69.       }
  70.     }
  71.   }
  72.  
  73. });
Advertisement
Add Comment
Please, Sign In to add comment