Сделал бота, который при донате добавляет инфу в MySQL и Rich Presense
Но когда кто-то отправляет донат, бот в cli пишет:
(node:12916) UnhandledPromiseRejectionWarning: DiscordAPIError: Invalid Form Body
user_id: Value "Amogus" is not snowflake.
at C:\Users\Vlad\Desktop\1\donatealerts_watcher-master\node_modules\discord.js\src\client\rest\RequestHandlers\Sequential.js:85:15
at C:\Users\Vlad\Desktop\1\donatealerts_watcher-master\node_modules\snekfetch\src\index.js:215:21
at processTicksAndRejections (internal/process/task_queues.js:93:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:12916) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:12916) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Сам код:
const
configuration = require('./config.json'),
io = require('socket.io-client'),
socket = io('wss://socket.donationalerts.ru:443'),
Discord = require('discord.js'),
client = new Discord.Client(),
id = require('uniqid'),
mysql = require('mysql2/promise'),
con = mysql.createPool(configuration.mysql);
socket.emit('add-user', { token: configuration.key, type: "minor" });
client.login(configuration.token)
socket.on('donation', async message => {
const cheque = id('cheque-');
message = JSON.parse(message);
user = await client.fetchUser(message.username);
if (!user) return;
const [data] = await con.query(`SELECT * FROM users WHERE user_id = ?`, [user.id]);
if (data[0]) {
await con.query(`UPDATE users SET balance = balance + ? WHERE user_id = ?`, [message.amount_main, user.id])
} else {
await con.query(`INSERT INTO users (user_id, balance) VALUES (?,?)`, [user.id, message.amount_main]);
}
await con.query(`INSERT INTO donates (authorID, revieced, currency, transform, message, cheque) VALUES (?, ?, ?, ?, ?, ?)`, [message.username, +message.amount, message.currency, +message.amount_main, message.message, cheque])
const embed = new Discord.RichEmbed()
.setAuthor(`Получен новый донат от ${user.tag}!`, user.displayAvatarURL)
.setDescription(`Получено **\`${message.amount}${message.currency} => ${message.amount_main}RUB\`**\nЧЕК АЙДИ: ${cheque}\n\n${message.message}`, true)
let channel = client.channels.get(configuration.channel);
if (channel) channel.send(embed).catch(e => {});
})
Конфиг:
{
"token": "discord token",
"key": "donationalerts token",
"mysql": {
"host": "",
"user": "",
"password": "",
"database": "",
"charset": "utf8mb4",
"insecureAuth": true
},
"channel": "840897171746455593"
}
Помогите, пожалуйста.