This commit is contained in:
parent
529cc4162b
commit
d960014aee
@ -45,10 +45,36 @@ module.exports = {
|
||||
await interaction.reply(`Selecionaste: \r nome:${nome}\r id:${nome.id} \r cargo:<@&${cargo}>(${cargo}) \r url:${url}\r idavatar:${idavatar}`);
|
||||
|
||||
|
||||
const [rows] = await conn.execute(
|
||||
|
||||
|
||||
|
||||
|
||||
// 1 - Verificar se já existe no banco
|
||||
const [existing] = await db.execute(
|
||||
`SELECT * FROM membros WHERE discord_id = ?`,
|
||||
[nome.id]
|
||||
);
|
||||
|
||||
if (existing.length > 0) {
|
||||
return await interaction.reply({ content: `❗ O membro ${nome.username} já está registrado no banco de dados.`, ephemeral: true });
|
||||
}
|
||||
|
||||
// 2 - Inserir no banco
|
||||
const conn.execute(
|
||||
`INSERT INTO users (discord_id, discord_avatar, discord_username, cargo, level) VALUES (?, ?, ?, ?, ?)`,
|
||||
[nome.id, idavatar,nome.username, cargo, "0"]
|
||||
);
|
||||
|
||||
|
||||
// 3 - Pegar o membro na guilda
|
||||
const member = await interaction.guild.members.fetch(nome.id);
|
||||
|
||||
// 4 - Verificar se o membro já tem o cargo
|
||||
if (member.roles.cache.has(cargo)) {
|
||||
return await interaction.reply({ content: `❗ O membro ${nome.username} já possui o cargo <@&${cargo}>.`, ephemeral: true });
|
||||
}
|
||||
|
||||
// 5 - Adicionar o cargo
|
||||
await member.roles.add(cargo);
|
||||
|
||||
},
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user