• 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.

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

Oblivion

Member
CC Dev Team
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_JinX: sup
      Back
      Top