[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
  • No one is chatting at the moment.
  • @ QM|T:
    you going to use it
  • @ lurch6661:
    when i find it ill send it
  • @ lurch6661:
    i dont have 9.00
  • @ QM|T:
    :xD: me either hahaha
  • @ lurch6661:
    lol
  • @ QM|T:
    lol
  • @ lurch6661:
    man i got some white widow
  • @ QM|T:
    nice
  • @ lurch6661:
    its a sativa though
  • @ QM|T:
    it is what it is right haha
  • @ lurch6661:
    i actually have been making thc chocolate
  • @ lurch6661:
    lol yup
  • @ QM|T:
    haha ok
  • @ lurch6661:
    so what kinda soundbar did u get
  • @ lurch6661:
    i just pawned one for 2 00 bucks
  • @ QM|T:
    thi one is from LG wireless it was 250 euros
  • @ QM|T:
    this
  • Chat Bot:
    rr88comse4 is our newest member. Welcome!
  • @ lurch6661:
    blast this
  • @ QM|T:
    nice
  • @ QM|T:
    but i have to go im going to my moms house
  • @ QM|T:
    ck later on tho
  • @ lurch6661:
    ok bro tc
  • @ QM|T:
    tc bro
      @ QM|T: tc bro