15 lines
902 B
JavaScript
15 lines
902 B
JavaScript
const client = global.discord_client
|
|
const pool = global.db_pool;
|
|
|
|
const execute = async (interaction) => {
|
|
const pairingCode = interaction.options.getString("pairing-code");
|
|
const discordID = interaction.user.id;
|
|
const [row] = await pool.query('SELECT * FROM users WHERE discordId = ?', [discordID]);
|
|
if (row) return interaction.reply({ content: "You have already linked your account", ephemeral: true });
|
|
const [pairing] = await pool.query('SELECT * FROM users WHERE pairingCode = ?', [pairingCode]);
|
|
if (!pairing) return interaction.reply({ content: "Invalid pairing code", ephemeral: true });
|
|
await pool.query('UPDATE users SET discordId = ?, discordDisplayName = ?, pairingCode = NULL WHERE pairingCode = ?', [discordID, interaction.user.displayName, pairingCode]);
|
|
return interaction.reply({ content: "Successfully linked your account", ephemeral: true });
|
|
}
|
|
|
|
module.exports = { execute } |