[JS] [Discord.js] Send Random Hex Value.

  • Hello Guest! Welcome to ConsoleCrunch, to help support our site check out the premium upgrades HERE! to get exclusive access to our hidden content.
  • Unable to load portions of the website...
    If you use an ad blocker addon, you should disable it because it interferes with several elements of the site and blocks more than just adverts.
  • Read Rules Before Posting Post Virus Scans with every program.

Oblivion

Member
CC Dev Team
Jul 25, 2016
26
28
73
Read the comments in the source code to understand what you need to change.
Check out more discord bot examples on my GitHub discord bot example repo.

Code:
const Discord = require('discord.js'); //Make sure to install discord.js using NPM.
const client = new Discord.Client();

const prefix = '!'; //Change the prefix to whatever you want to use on your bot.

function cmd(str, msg) { //Function for commands.
    return msg.content.startsWith(prefix + str);
}

client.on('message', message => {

    if (cmd('hex', message)) {
      let color = ((1 << 24) * Math.random() | 0).toString(16); //Generates random hex value.
      let embed = new Discord.RichEmbed() //Embeds.
            .setTitle(`#${color}`)
            .setColor(`#${color}`);
     message.channel.send({embed: embed});
  }

})
client.login(TOKEN_HERE); //Replace "TOKEN_HERE" with your bots token.
 
Last edited:
General chit-chat
Help Users
  • Chat Bot:
    BluntRGH is our newest member. Welcome!
  • Chat Bot:
    QM|T_JinX has joined the room.
  • Chat Bot:
    QM|T_JinX has joined the room.
  • Chat Bot:
    QM|T_JinX has joined the room.
  • Chat Bot:
    xoso66rucom is our newest member. Welcome!
  • Chat Bot:
    xoso66rucom1 is our newest member. Welcome!
  • Chat Bot:
    jtarules89 has posted a new reply in the thread "SPRX OASIS 2.1 CFW/HEN".
  • Chat Bot:
    QM|T_JinX has joined the room.
  • Chat Bot:
    Christo has joined the room.
  • Chat Bot:
    QM|T_JinX has joined the room.
  • Chat Bot:
    Ihxtehxes is our newest member. Welcome!
  • Chat Bot:
    taeganwilson is our newest member. Welcome!
  • Chat Bot:
    Christo has joined the room.
  • Chat Bot:
    kirat is our newest member. Welcome!
  • Chat Bot:
    Christo has joined the room.
  • Chat Bot:
    QM|T_JinX has joined the room.
  • Chat Bot:
    testsdsdsd is our newest member. Welcome!
  • Chat Bot:
    QM|T_JinX has joined the room.
  • Chat Bot:
    QM|T_JinX has joined the room.
  • Chat Bot:
    predador44 is our newest member. Welcome!
  • @ LoveModz:
    Been a very long time.
  • @ QM|T_JinX:
    sup
  • Chat Bot:
    go88club4comm is our newest member. Welcome!
  • Chat Bot:
    QM|T_JinX has joined the room.
      Chat Bot: QM|T_JinX has joined the room.