Помогите с discord.js
Выводит вот это
C:\Users\KYRAPATKA\Desktop\discord-bot\index.js:38
u.sms++; //Подчет сообщений участника
^
TypeError: Cannot read properties of undefined (reading 'sms')
at Client.<anonymous> (C:\Users\KYRAPATKA\Desktop\discord-bot\index.js:38:5)
at Client.emit (node:events:538:35)
at MessageCreateAction.handle (C:\Users\KYRAPATKA\Desktop\discord-bot\node_m
odules\discord.js\src\client\actions\MessageCreate.js:34:18)
at Object.module.exports [as MESSAGE_CREATE] (C:\Users\KYRAPATKA\Desktop\dis
cord-bot\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js
:4:32)
at WebSocketManager.handlePacket (C:\Users\KYRAPATKA\Desktop\discord-bot\nod
e_modules\discord.js\src\client\websocket\WebSocketManager.js:351:31)
at WebSocketShard.onPacket (C:\Users\KYRAPATKA\Desktop\discord-bot\node_modu
les\discord.js\src\client\websocket\WebSocketShard.js:444:22)
at WebSocketShard.onMessage (C:\Users\KYRAPATKA\Desktop\discord-bot\node_mod
ules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
at WebSocket.onMessage (C:\Users\KYRAPATKA\Desktop\discord-bot\node_modules\
ws\lib\event-target.js:199:18)
at WebSocket.emit (node:events:526:28)
at Receiver.receiverOnMessage (C:\Users\KYRAPATKA\Desktop\discord-bot\node_m
odules\ws\lib\websocket.js:1137:20)
Код index.js
const config = require("./config.json");
const { Client, Intents } = require("discord.js");
const Discord = require('discord.js');
const Embed = new Discord.MessageEmbed()
const profile = require('./profile.json')
const fs = require('fs');
const client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES
]
});
client.login("xxxxxxxxxxxxxx"); //Где token пишем токен бота.
client.on("message", message => { //Пришло сообщение.
console.log("Игрок >> " + message.author.tag + "Отправил сообщения >> " + message.content); //message.author.tag содержит в себе тег автора.
})
client.on('message', async message => {
const uid = message.author.id
const 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)
});
});