Бесплатный, самописный скрипт Discord бота (NodeJS)

Годный бот?

  • Да

    Голосов: 1 100.0%
  • Нет

    Голосов: 0 0.0%

  • Всего проголосовало
    1

TheRobbCode

Новичок
Статус
offline
Регистрация
04.05.2019
Сообщения
2
Репутация
3
Всем привет, друзья.

Завалялся у меня скрипт прекрасного игрового бота Discord.js.

Т.к. бот не прославился, я решил слить его скрипт, может кому-то понадобится и кто-то сможет реализовать мою идею.

Скрипт писал сам, в одиночку.

Настройка бота:

1) В самом низу кода вставляем токен (вход для бота).
2) Подключите discord.js через npm
3) Создайте файл profile.js и напишите в нём {}

Дальше рассказывать не буду, ибо это уже основы основ....если вы уж не знаете, то посмотрите гайд, как создать бота в дискорде, а потом пользуйтесь моим кодом.

Поставьте +rep, если бот годный.

JavaScript:
const Discord = require('discord.js');
const { Client, RichEmbed } = require('discord.js');
const fs = require('fs');
const client = new Discord.Client();

let profile = require('./profile.json')
const bot_name = "RiscoY"

var thr;
var secret_word;
var words_game = false;
var otvet;


client.on('ready', () => {
  console.log(`Logged in as ${client.user.tag}!`);
  client.user.setActivity("!r help")
  var generalChannel = client.channels.get('559426727357448216')
    generalChannel.send(bot_name + " successfully conected to Discord server.")
});


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


    function flood() {
        for(var spam = 0; spam < 15; spam++) {
        msg.channel.send("flood flood flood flood flood flood flood flood");
        }
        thr = false;
    }

    if(msg.author.bot) return;
    if(msg.author.id === client.user.id) return;

    let uid = msg.author.id;

    if(!profile[uid]) {
        profile[uid] = {
            coins: 0,
            warns: 0,
            xp: 0,
            lvl: 0,
            bitcoins: 0.001,
            ferms: 1,
            discord: 0,
            skype: 0,
            teamspeak: 0,
            total_msg: 0
        };
    };
    let u = profile[uid];
    fs.writeFile('./profile.json', JSON.stringify(profile), (err)=>{
        if(err) console.log(err);
    });

     u.xp++;
     u.total_msg++;
     u.bitcoins+= 0.001 * u.ferms


     //levels
     if(u.xp >= 50 ) {
        u.lvl++;
        u.coins += 100;
        msg.reply("Congratulations, you have reached level " + u.lvl + ", good luck!!");
        u.xp = 0;
     }

    if (msg.content === '!r info') {
    const embed = new RichEmbed()
      .setTitle('Bot Info:')
      .setColor(0xFF0000)
      // Set the main content of the embed
      .setDescription('authors: TheRobbCode, Sasha');
    // Send the embed to the same channel as the message
    msg.channel.send(embed);
  }

    
     if(msg.content == '!r ferm') {
        msg.channel.send('Information about farms and bitcoins:\n1) When you write to the chat, you are given 0.001 bitcoin by default, having one farm. This amount depends on the number of your farms. If you have 20 farms, then when you write in chat, you will be given 0.020 bitcoin\n\n2)!r shop - You can buy bitcoin farms in the store\n3) !r sell - Sell bitcoins\n\nBitcoin exchange rate: 1200 coins');
     }



    if(msg.content == "!r drugs") {
      msg.channel.send("!drugs discord - improves your condition, you become cheerful and strong (can be purchased in the store !r shop) Your nerves are getting stronger.\n!drugs skype - your eyes burst and 50% of your nerves fail to work (can be purchased in the store !r shop)\n!drugs teamspeak - You feel good but become homeless due to addiction (can be purchased in the store !r shop)");
    }




 
  if (msg.content === '!r help') {
    const embed = new RichEmbed()
      .setTitle('Help-Menu:')
      .setColor(0xFF0000)
      // Set the main content of the embed
      .setDescription('HELP-MENU:\n\nCommands:\n!r profile - your profile\n!r shop - shop\n!r ferm - information about bitcoins and farms\n!r drugs - drug information\n!r bet - play the lottery for 100 coins. Everyone has the same chance to win. Users of all servers participate in the lottery\n!r info - full bot info\n\nGAMES:\n!words - Game "Guess the word"\n(game information: !info words)\n\nFunctions:\n!r flood - is used to to call admin or break the chat\n!r random - random number from 1 to 10\n')
    // Send the embed to the same channel as the message
    msg.channel.send(embed);
  }



  if(msg.content == '!r sell') {
      if(u.bitcoins < 1) {
    msg.reply('Bitcoins can not be sold if their number is less than 1.000, if this is a mistake, contact your administrator.')
      }
      if(u.bitcoins >= 1) {
          var sum_add = u.bitcoins * 1600;
          u.coins += sum_add;
        msg.reply('You sold ' + u.bitcoins + ' bitcoins and received ' + sum_add + ' coins')
          u.bitcoins-=u.bitcoins;
      }
  }



  if(msg.content == '!r bet') {
      u.coins-=100;
      var rand_sopernik = 0;
      var rand_play;
      var win;
      if(rand_sopernik == 0) {
    var rand_play = Math.floor(Math.random() * 51);
    chance = 25;
    if(rand_play >= chance) {
    u.coins+=200;
    msg.reply("You won 100 coins\n\nNumber of participants: 2")
    }
    if(rand_play < 25) {
     msg.reply("You lost 100 coins\n\nNumber of participants: 2")
    }
      }
  }



   if(msg.content == '!info words') {
      msg.channel.send("1) You need to answer the question that the bot will ask you;\n2) Ответ всегда с маленькой буквы и в 1 слово\n3) To answer, use: !r aswer слово\n4) To complete the game, use: !r stop");
   }

   if(msg.content == "!r balance") {
      msg.reply("Your Balance: " + u.coins + " coins" + "\nBitcoins: " + u.bitcoins);
   }


if(msg.content == '!words' && words_game != true) {
    if(words_game == true && msg.content ==  '!words') {
    msg.reply('The game has already started!\nsTo finish the game, use: !r stop')
    }
    var rand_word = Math.floor(Math.random() * 2);
    words_game = true;
    if(rand_word == 0) {
    secret_word = "orange";
    if(secret_word == "orange") {
        msg.reply("We eat it every day, it's a lot of vitamin C.\n\nTo answer the question, use: !r answer word");
        msg.channel.send("random num: " +  rand_word)
    }
}
    if(rand_word == 1) {
        words_game = true;
     secret_word = "microsoft";
    if(secret_word == "microsoft") {
        msg.channel.send("random num: " + rand_word)
        msg.reply("Over big company: this company created windows windows\n\nTo answer the question, use: !r answer word");
    }
    }
}

if(msg.content == "!r stop" && words_game == false) {
 msg.reply("The game isn't running!");
}


function answer_t() {
    u.coins += 100;
    msg.reply('Greetings! Correct answer!\nYou got 100 coins.\nYour Balance: ' + u.coins);
    otvet = true;
    words_game = false;
}








//aswers
if(msg.content == "!r answer orange" && secret_word == "orange") {
 answer_t();
}
 if(msg.content == "!r answer microsoft" && secret_word == "microsoft") {
 answer_t();
 }
else if(words_game == true && otvet != true && msg.content != "!words" && msg.content == "!r answer orange" && msg.content == "!r answer microsoft") {
    msg.reply('Wrong answer!');
}
//aswers







//errors
if(msg.content == '!r stop' && words_game == true) {
    words_game = false;
    msg.reply('The game is over');
}
//errors









  if(msg.content == '!r flood') {
    if(thr != true) {
        msg.channel.send("Flood will start in 30 seconds")
        setTimeout(flood, 30000);
        thr = true;
    }
  }


  if(msg.content == '!r random') {
   var rand = Math.floor(Math.random() * 11);
            msg.channel.send("Random number: " + rand);
  }



  if(msg.content == '!r shop') {
   msg.channel.send('SHOP-MENU:\n\n1) lvl-potion\nDesc: increases your level by 1 unit)\nPrice: 150\n\n2) box-money\nDesc: when you buy falls from 0 to 200 coins\nPrice: 100\n\n3) bitcoin-ferm\nDesc: adds you 1 farm\nPrice: 200\n\n4) drug-discord\nDesc: !r drugs\nPrice: 999\n\n5) drug-skype\nDesc: !r drugs\nPrice: 666\n\n6) drug-teamspeak\nDesc: !r drugs\nPrice: 333 \n\nTo buy, use: !buy item (!buy box-money...)');
  }









  if(msg.content == '!buy lvl-potion') {
      if(u.coins < 150) {
          msg.reply("Not enough coins to buy\nYour Balance: !r balance")
      }
      if(u.coins >= 150) {
          u.lvl++;
          u.coins -= 150;
          msg.reply('Level Up!\nYour Level: ' + u.lvl + '\nYour balance: ' + u.coins)
      }
  }
  if(msg.content ==  '!buy box-money') {
      if(u.coins < 100) {
          msg.reply("Not enough coins to buy\nYour Balance: !r balance")
      }
      if(u.coins >= 100) {
          var rand = Math.floor(Math.random() * 201);
          u.coins -= 100;
          u.coins += rand;
          if(rand >= 100) {
              msg.reply("You're lucky, the box dropped " + rand + " coins.\nYour Balance: " + u.coins, " (+" + rand-100 + "coins)");
          }
          if(rand <= 99) {
              msg.reply("You're out of luck, the box dropped " + rand + " coins.\nYour Balance: " + u.coins + "test");
          }
      }
  }
  if(msg.content == '!buy bitcoin-ferm') {
      if(u.coins < 200) {
          msg.reply("Not enough coins to buy\nYour Balance: !r balance")
      }
      if(u.coins >= 200) {
          u.ferms++;
          u.coins -= 200;
          msg.reply('You have successfully purchased the farm!')
      }
  }

var rand_police;

  if(msg.content == '!buy drug-discord') {
      if(u.coins < 999) {
          msg.reply("Not enough coins to buy\nYour Balance: !r balance")
      }
      if(u.coins >= 999) {
          u.discord++;
          u.coins -= 999;
          rand_police = Math.floor(Math.random() * 3);
        if(rand_police == 0 || rand_police == 1) {
          msg.reply('You have successfully bought and used the "drug-discord!"')
      }
         if(rand_police == 2) {
            u.coins-=100;
            msg.reply('Unfortunately, you noticed as you used drugs that you are not put in jail, you pay 100 coins. But you enjoyed the drug "drug-discord"')
         }
      }
  }
  if(msg.content == '!buy drug-skype') {
      if(u.coins < 666) {
          msg.reply("Not enough coins to buy\nYour Balance: !r balance")
      }
      if(u.coins >= 666) {
          u.skype++;
          u.coins -= 666;
          rand_police = Math.floor(Math.random() * 3);
        if(rand_police == 0 || rand_police == 1) {
          msg.reply('You have successfully bought and used the "drug-skype!"')
      }
         if(rand_police == 2) {
            u.coins-=100;
            msg.reply('Unfortunately, you noticed as you used drugs that you are not put in jail, you pay 100 coins. But you enjoyed the drug "drug-skype"')
         }
      }
  }
  if(msg.content == '!buy team-speake') {
      if(u.coins < 333) {
          msg.reply("Not enough coins to buy\nYour Balance: !r balance")
      }
      if(u.coins >= 333) {
          u.teamspeak++;
          u.coins -= 333;
          rand_police = Math.floor(Math.random() * 3);
        if(rand_police == 0 || rand_police == 1) {
          msg.reply('You have successfully bought and used the "team-speake"')
      }
         if(rand_police == 2) {
            u.coins-=100;
            msg.reply('Unfortunately, you noticed as you used drugs that you are not put in jail, you pay 100 coins. But you enjoyed the drug "teap-speake"')
         }
      }
  }




      // Set the color of the embed



  if (msg.content === '!r profile') {
    const embed = new RichEmbed()
      .setTitle('Your Profile:')
      .setColor(0xFF0000)
      // Set the main content of the embed
      .setDescription('ID: '+ msg.author.id +'\n\nCoins: ' + u.coins + '\nLevel: ' + u.lvl + '\nXP: ' + u.xp +  '\n\nDrugs used:\ndrug-discord: '  + u.discord  + '\ndrug-skype: ' + u.skype  + '\ndrug-team-speak: '  + u.teamspeak + '\n\nBitcoin ferms: ' + u.ferms + "\nBitcoins: " + u.bitcoins + "\n\nTotal messages: " + u.total_msg)
    // Send the embed to the same channel as the message
    msg.channel.send(embed);
  }
});



client.login('token');




//message.channel.send('pong');
 
  • Годно
Реакции: FLKN

TheRobbCode

Новичок
Статус
offline
Регистрация
04.05.2019
Сообщения
2
Репутация
3
Если возникла ошибка, то полностью сотрите строки:
16,18,19.