Create register command

This commit is contained in:
baz 2023-12-18 21:57:06 +00:00
parent 590ca18f18
commit 1f504ae0c4
1 changed files with 25 additions and 0 deletions

View File

@ -0,0 +1,25 @@
const { SlashCommandBuilder } = require('discord.js');
const { Users } = require ('../../dbObjects.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('register')
.setDescription('Manually registers the user into the user database.'),
async execute(interaction) {
// interaction.user is the object representing the user who ran the command
// interaction.member is the GuildMember object, which represents the user in the specific guild
const user = await Users.findOne({ where: { discord_id: interaction.user.id } })
.catch((err) => {
console.log(err);
});
if (user) return interaction.reply(`User "${interaction.user.username}" is already registered`);
await Users.create({ discord_id: interaction.user.id, username: interaction.user.username })
.then(await interaction.reply(`${interaction.user.username} was manually registered.`))
.catch((err) => {
console.log(err);
});
},
};