Answer the question
In order to leave comments, you need to log in
Economy/shop bot on Discord.js?
Hello! I need help, I'd like to add a shop/coin system to my system. People communicate, and for communication they receive coins. For coins, they could buy roles in the store, which, for example, I would show in the code. I understand that it must be done from scratch. But if you saw such a source somewhere, could you give a link or help with the development of such a bot, suggest what needs to be done and how. What and where to look. Thanks in advance
Answer the question
In order to leave comments, you need to log in
Here is the code:
To make it work you need the fs module.
First you create a file (where your index.js is located) called profile.json , then write this in it {}
and run the bot
In index.js:
let profile = require('./profile.json') //Подключаем профили, эту строку надо поставить в самом начале кода после подключения всех модулей
client.on('message', async message => {
let uid = message.author.id
let u = profile[uid]
if (!profile[uid]){ //Если нету профиля, создаем
profile[uid] = {
sms:0,
xp:0,
lvl:0,
money:0,
};
};
u.sms++; //Подчет сообщений участника
u.xp++;
u.money++; //За каждое сообщение по монетке)
if (u.xp>= (u.lvl * 50)){ //Если участник написал 50 сообщений, он получает левел
u.xp = 0;
u.lvl += 1;
}
fs.writeFile('./profile.json',JSON.stringify(profile),(err)=>{ //Записываем в файл
if(err) console.log(err)
});
};
${u.money}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question