Making a discord bot with javascript. part4 - Paperytxt/bot.txt GitHub Wiki

Lets work on embeds, shall we? its pretty easy so lets get a example.

Embed Test

Now lets look at this code.

if(command == 'test'){
    var embed = new Discord.RichEmbed()
            .addField('Field', "Field2", true)
            .addField('You will need hex colours. if you need help google "colour picker"', 'hex', true)
            .addField("Blank Field", "blank")
            .addBlankField()
            .setColor('FFFFFF')
            .setAuthor(`Author can also hold a image.`, image)
            .setFooter('This is the footer. at the very bottom. can also hold a picture', image)
            .setImage('image')
            message.channel.send(embed)
}

var embed = new Discord.RichEmbed() says that this is a embed and need to treat it like one.

.addField() Adds on to that said embed.

.addField(,true) is a inline. puts them in a row. but it didnt show up.

.addBlankField() Easy line break.

.setColor() Guess. Colour Picker

.setTitle() I for got to put it in that embed but its like author without the image.

.setAuthor() Gets put above the title.

.setFooter() always gets put at the bottom. can hold an image.

.setImage() guess again.

.setTimestamp() another thing I forgot to show. tells you the current date and time. next to footer.

nearly all forms of markdown can be put in. even Masked links.

that's just about it for now, I know its been short but next time, I don't know what ill do for next time.

finishing product

const Discord = require('discord.js');
const bot = new Discord.Client();
const fs = require("fs");
const coins = require("./coins.json")
const ownerid = "yourid"
bot.on('ready', () => {
    bot.user.setActivity("Being a bot is hard.")
    console.log("Bot is online.")
});
bot.on('message', function(message){
    if(message.content == 'hello')
    {
message.reply("Hi there!")
    }
});
bot.on('message', function(message){
// if user is bot it returns
    if(message.author.bot) return;
// if you want to, make a role called moneyban to prevent people from gaining money.
//     if(message.member.roles.some(r=>["moneyban"].includes(r.name)) )return;
    let coinAmt = Math.floor(Math.random() * 7) + 1
  let willithappen = Math.floor(Math.random() * 18 ) + 1

  if(willithappen == "1" ){
    // checks if they don't have a pocket. if not it makes a pocket for them.
    if(!coins[message.author.id]){
        coins[message.author.id] = {
           coins: 0
        }
    }
// adds the money on
    coins[message.author.id] = {
        coins: coins[message.author.id].coins + coinAmt
    };
    fs.writeFile('./coins.json', JSON.stringify(coins), err =>{
        if (err) console.log(err)
    })
// sends message to the authors dm and then deletes itself after 60 seconds.
          message.author.send(`you got ${coinAmt}`).then(msg => {msg.delete(60000)})
          console.log(`${message.author.tag} got ${coinAmt}`)
}
  
});

bot.on("message", async message => {
const prefix = ">"
  if(message.content.indexOf(prefix) !== 0) return;
if(message.author.bot) return;
const args = message.content.slice(prefix.length).trim().split(" ")
const command = args.shift().toLowerCase();
if(command === 'money'){
if(!coins[message.author.id]){
        coins[message.author.id] = {
           coins: 0
        }
    }

     message.reply("you have" + coins[message.author.id].coins)
}}
if(command == 'embed'){
    var embed = new Discord.RichEmbed()
            .addField('Field', "Field2", true)
            .addField('You will need hex colours. if you need help google "colour picker"', 'hex', true)
            .addField("Blank Field", "blank")
            .addBlankField()
            .setColor('FFFFFF')
            .setAuthor(`Author can also hold a image.`, image)
            .setFooter('This is the footer. at the very bottom. can also hold a picture', image)
            .setImage('image')
            message.channel.send(embed)
}

 if(command === "say") {
// gives the message a better look, it would look like hello,world but adding this changes it to hello world.
 const sayMessage = args.join(" ");
// this deletes the user message and ignores the error it generates.
    message.delete().catch(O_o=>{});
//sends the message you sent. 
  message.channel.send(says)
 }
if(command == 'playstatus'){
// blocks other users.
if(message.author.id !== ownerid) return message.reply("sorry you cant do that");
// same thing as sayMessage
 const playStatus = args.join(" ");
// sets the playstatus
 bot.user.setActivity(`${playStatus} | any thing else you wanna add.`)
// guess what this does?
message.reply("sure thing.")
}
});
bot.login("your-veryepic&token");