mars0j
mars0j

Reputation: 27

discord.js TypeError Cannot Read properties of undefined (reading 'options')

I created a ban command for my discord bot, but I encountered such an error

code :

module.exports = {
    name: "ban",
    permission: "BAN_MEMBERS",
    options: [
        {
            name: "target",
            description: "banlamak için bir hedef seçin.",
            type: "USER",
            required: true,



        },
        {
            name: "reason",
            description: "banlamak için bir sebep seçin.",
            type: "STRING",
            required: true,

        },
        {
            name: "messages",
            description: "Seçeneklerden birini seç.",
            type: "STRING",
            required: true,
            choices: [
                {
                    name: "hiç birini silme",
                    value: 0
                },
                {
                    name: "önceki 7 gün",
                    value: 7
                }


            ]
        },


    ],

    execute(client, interaction) {
        const Target = interaction.options.getMember('target');

        if (Target.id === interaction.member.id)
        return interaction.followUp({embeds: [new MessageEmbed().setColor('BLACK').setDescription(`⛔ kendini yasaklayamazsın. `)]})

        if (Target.permissions.has('ADMINISTRATOR'))
        return interaction.followUp({embeds: [new MessageEmbed().setColor('BLACK').setDescription(`⛔ Bir Yöneticiyi Yasaklayamazsınız. `)]})

        const Reason = interaction.options.getString('reason');

        if (Reason.length > 512)
        return interaction.followUp({embeds: [new MessageEmbed().setColor('BLACK').setDescription(`⛔ sebep 512 karakteri geçemez. `)]})
        
        const Amount = interaction.options.getString('messages');

        Target.ban({ days : Amount, reason : Reason})

        interaction.followUp({embeds : [new MessageEmbed().setColor("WHITE").setDescription(`✅ **${Target.user.username}** banlanmıştır. `)]})

        
        
    }
}

Upvotes: 0

Views: 958

Answers (1)

Cartion
Cartion

Reputation: 157

if the error occurs on the first line where this is executed

const Target = interaction.options.getMember('target');

then the issue could be caused by options not being a member of the interaction. Are you sure that the interaction you are running is a command interaction. You could check this easily by adding this call before anything else. If nothing is ran after this is executed then it means the interaction you are interacting with is not a command so options won't exist on that interaction.

if (!interaction.isCommand()) return;

Upvotes: 1

Related Questions