#Help with setting roles

14 messages · Page 1 of 1 (latest)

quaint breach
#

Hey guys,I want to give the player that started the command a specific role and I also want to get the role id from the name.

quasi ingot
#

• What's your exact discord.js npm list discord.js and node node -v version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.

quaint breach
#

const {SlashCommandBuilder} = require('discord.js');
const Account = require('../schemas/AccountSchema.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('linkaccount')
.setDescription('Link Valorant account to Discord account.')
.addStringOption(option =>
option.setName('input')
.setDescription("The username of the player")),
async execute(interaction){
const username = interaction.options.getString("input");
if (!username.includes('#'))
return await interaction.reply('You have entered an invalid Valorant username and tag!');

    const account = Account.find({discordId:interaction.user.id});

    if (account.length > 0) {
        await Account.deleteMany({ discordId: interaction.user.id })
    }

    try{
        await Account.create({
            username: interaction.user.username,
            discordId: interaction.user.id,
            valorantAccount: username
        })
        const role = interaction.option.guild.getRole('Bronze 1')
        const member = interaction.options.getMember('Aronka');
        interaction.member.roles.add(role)


        await interaction.reply('Account successfully linked');
    }catch(error){
        console.error(error)
    }
},

};

#

this code doesnt work

finite oak
#

You dont have a role or user option so .getMember() and .getRole() won’t work. You only have a string option

#

Another thing, the options.get…() method takes the option name which is always lowercase

quaint breach
#

How can i make a command that gets the role and adds it to the userwithout them having to input it themselves?

uneven dagger
#

Make sure that the interaction is used in the correct guild and not in DMs

quaint breach
#

thanks a lot!

uneven dagger
#

No problem :D

quaint breach
#

DiscordAPIError[50013]: Missing Permissions

#

Why do I get this error?

#

the bot has administrator rights