ProgrammingMy Code Snippet Collection [Discord Bot] [JS]
Posted:

ProgrammingMy Code Snippet Collection [Discord Bot] [JS]Posted:

module
  • Resident Elite
Status: Offline
Joined: Mar 13, 20168Year Member
Posts: 260
Reputation Power: 30
Status: Offline
Joined: Mar 13, 20168Year Member
Posts: 260
Reputation Power: 30
Learn to create your bot? Simple and easy steps.
Forums/t=7802265/writing-your-fir...orial.html

All of these snippets were written by me so if you have any questions feel free to ask.


Generate Random String

function generate_randomstring(length) {
    var result           = '';
    var characters       = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+-=[]{};:"\|,./<>?`~';
    var charactersLength = characters.length;
    for ( var i = 0; i < length; i++ ) {
       result += characters.charAt(Math.floor(Math.random() * charactersLength));
    }
    return result;
 }


Usage: var example = generate_randomstring(LENGTH IN INTEGER);

Generate Random Number

function generate_randomnumber(length) {
    var result           = '';
    var characters       = '0123456789';
    var charactersLength = characters.length;
    for ( var i = 0; i < length; i++ ) {
       result += characters.charAt(Math.floor(Math.random() * charactersLength));
    }
    return result;
 }


Usage: var example = generate_randomnumber(AMOUNT OF DIGITS);

Send Messages On A Timer

var interval = setInterval (function ()
{
bot.channels.get('CHANNEL ID TO SEND MESSAGES').send("ENTER YOUR MESSAGE TO SEND");
}, 1 * 10000);

// Every 1000 equals 1 second.


React In Specific Channel When A Message Was Sent

if (message.channel.id == "CHANNEL ID YOU WANT IT TO REACT IN") {
   message.react('');
}


Simple Poll By Me

      const embed = new Discord.RichEmbed()
      .setColor("#4D6E4E")
      .setTitle(msgArgs) // POLL QUESTION
      .setDescription("`React for a yes or no answer.` \n \n Poll By: " + `${message.author}`)
      message.channel.send({embed}).then(messageReaction => {
      messageReaction.react('');
      messageReaction.react('');
      });


I may add some from my private bot later with custom integrated systems.

The following 1 user thanked module for this useful post:

DHCP (10-04-2020)
Users browsing this topic: None
Jump to:


RECENT POSTS

HOT TOPICS