Error - const roleId = interaction.options.getString('role_id');

Morning all,

I've been having this error since last night and I've seen a few people with the same error on Stackoverflow but didn't find any working solutions... This is for my Role React Command and I've getting the error seen in the title. Any help would be great šŸ™‚

addreactrole.js - Broken Area
module.exports = {
    data: new SlashCommandBuilder()
        .setName('addrolereact')
        .setDescription('Reaction Role Addition')
        .addStringOption(option =>
            option
                .setName('role_id')
                .setDescription('The ID of the role to assign when reacted to')
                .setRequired(true)
        )
        .addStringOption(option =>
            option
                .setName('message_text')
                .setDescription('Custom text for the reaction message')
        ),

        async execute(interaction, client) {
            const roleOption = interaction.options.getString('role_id'); // <-- This is the broken line        
            if (!roleOptionId) {
                return interaction.reply({ content: "Role ID option is missing or not a valid string.", ephemeral: true });
            }
        
            const roleId = roleOption;
            const customText = interaction.options.getString('message_text'); // 'message_text' is optional
        
            // Ensure roleId is a valid role ID
            const role = interaction.guild.roles.cache.get(roleId);
            if (!role) {
                return interaction.reply({ content: "Invalid role ID!", ephemeral: true });
            }


ready.js (Nothings wrong here but might be needed)
    // Import the interaction listener function and execute it
    const addReactRoleListener = require('../commands/utility/addreactrole.js');

    // Pass the 'client' object to the function when executing it
    addReactRoleListener.execute(client);
image.png
Was this page helpful?