Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can i get a user id from a .addUserOption?

Hey i made a xp system with discord-xp i wanted to make a slashcommand that can give a user xp. But everytime i give this user xp in the database there is a @ behind the user id and i want it without because otherwise the bot will not work.

Here is my Code:

const { SlashCommandBuilder } = require("@discordjs/builders");
const Levels = require('discord-xp');
const { MessageEmbed } = require('discord.js');
const client = require("../index")




module.exports = {
    data: new SlashCommandBuilder()
        .setName("addxp")
        .setDescription("add xp")
        .addUserOption((option) => option.setName('user').setDescription('add user xp').setRequired(true))
        .addNumberOption(option => option.setName('num').setDescription('Enter a number').setRequired(true)),
    async execute(client, interaction) {
        const user = interaction.options.user.id('target')
        const number = interaction.options.getNumber('num');
        var userID = interaction.user.id;
        const levels = await Levels.fetch(userID, interaction.guildId);



        Levels.appendXp(user, interaction.guild.id, number);



        interaction.reply(`**${user.tag}** got added ${number} XP.`);


    }
}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can use this:

const user = interaction.options.getUser('user')
const id = user?.id

Hope this helps!

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading