#Role Creator Command Not Working

1 messages · Page 1 of 1 (latest)

thorn marlin

Hey All,

Apologies if this is really simple... new to JS/discord bot dev stuff (day7),

I have a command that has most of this in it already that works & creates the role etc, but when I try it as a standalone it doesn't work?

const { SlashCommandBuilder, ChannelType, Colors, PermissionFlagsBits} = require('discord.js');

module.exports = {
    data: new SlashCommandBuilder()
        .setName('rolecreator.js')
        .setDescription('Create Nils Role Template'),
    async execute(interaction) {
        // Get guild from interaction, shorthands future calls
        const GUILD = interaction.guild;

        try {

            // Check if Test Role1 exists, if not create

            let TEST1_ROLE = GUILD.roles.cache.find(role => role.name === 'Test1 Role');

            if (!TEST1_ROLE) {
                TEST1_ROLE = await GUILD.roles.create({
                    name: 'Test1 Role',
                    color: Colors.Green,
                    reason: 'Automatically created by NilBot',
                });
            }

            interaction.reply({ content: "Command Success! Roles created.", ephemeral: true });

        }
        catch (err) {
            console.error(err)
            interaction.reply({ content: "Something went wrong with this command. Please check that the bot has the appropriate permissions to perform this action.\nIf this error persists, please contact the bot administrator.", ephemeral: true });
        }
    },
};```