Eldenlord
Eldenlord
DIAdiscord.js - Imagine an app
Created by Eldenlord on 3/3/2024 in #djs-questions
Get User language
I wanted to ask if its possible to get User language. I want to create a welcome Bot. And based from the User language, its should write the User a welcome message in his language. If there is no function to get user language, how should I do it?
5 replies
DIAdiscord.js - Imagine an app
Created by Eldenlord on 2/5/2024 in #djs-questions
mysql2 prepared statement
I wanted to ask you which way is the best for prepared statement in mysql2 First:
try {
const [rows] = await db.execute('SELECT * FROM account WHERE login = ?', [username]);

if (rows.length > 0) {
console.log("error");
return;
}

const [result] = await db.execute('INSERT INTO account (login, password, discord_id) VALUES (?, ?, ?)', [username, password, interaction.user.id]);

console.log("succesfull");
} catch (err) {
console.error('no DB:', err);
}
try {
const [rows] = await db.execute('SELECT * FROM account WHERE login = ?', [username]);

if (rows.length > 0) {
console.log("error");
return;
}

const [result] = await db.execute('INSERT INTO account (login, password, discord_id) VALUES (?, ?, ?)', [username, password, interaction.user.id]);

console.log("succesfull");
} catch (err) {
console.error('no DB:', err);
}
Second:
const checkUserQuery = 'SELECT * FROM account WHERE login = ?';
const checkUserParams = [username];
try {
const [result] = await connection.execute(checkUserQuery, checkUserParams);

if (result.length > 0) {
console.log("error");
return;
}

const createUserQuery = 'INSERT INTO account (login, password, discord_id) VALUES (?, ?, ?)';
const createUserParams = [username, password, interaction.user.id];

await connection.execute(createUserQuery, createUserParams);

console.log("succesfull");
} catch (err) {
console.error('no DB:', err);
}
}
const checkUserQuery = 'SELECT * FROM account WHERE login = ?';
const checkUserParams = [username];
try {
const [result] = await connection.execute(checkUserQuery, checkUserParams);

if (result.length > 0) {
console.log("error");
return;
}

const createUserQuery = 'INSERT INTO account (login, password, discord_id) VALUES (?, ?, ?)';
const createUserParams = [username, password, interaction.user.id];

await connection.execute(createUserQuery, createUserParams);

console.log("succesfull");
} catch (err) {
console.error('no DB:', err);
}
}
4 replies