Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· openaiHugging Face Suzhen/CodeChat

.addStringOption(option => ^ SyntaxError: Unexpected token '.' at…

  1. User

    .addStringOption(option => ^

    SyntaxError: Unexpected token '.' at internalCompileFunction (node:internal/vm:73:18) at wrapSafe (node:internal/modules/cjs/loader:1178:20) at Module._compile (node:internal/modules/cjs/loader:1220:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10) at Module.load (node:internal/modules/cjs/loader:1119:32) at Module._load (node:internal/modules/cjs/loader:960:12) at Module.require (node:internal/modules/cjs/loader:1143:19)
    at require (node:internal/modules/cjs/helpers:121:18) at Object. (D:\Йорарисс\index.js:17:19) at Module._compile (node:internal/modules/cjs/loader:1256:14)

    Node.js v18.17.1

    Process finished with exit code 1

    вот ошибка вот код const { ActionRowBuilder, ButtonBuilder, ButtonStyle, SlashCommandBuilder, EmbedBuilder } = require('discord.js');

    module.exports = { data: new SlashCommandBuilder() .setName('action') .setDescription('Взаимодействовать с участником') .addUserOption(option => option .setName('member') .setDescription('пользователь для взаимодействия') .setRequired(true)),

        .addStringOption(option =>
            option
                .setName('reason')
                .setDescription('Причина')
                .setRequired(false)
        ),
    async execute(interaction) {
        const target = interaction.options.getMember('member');
        const reason = 'Причина'; // Замените на вашу логику для получения причины
    
        const ban = new ButtonBuilder()
            .setCustomId('ban')
            .setLabel('Выдать бан')
            .setStyle(ButtonStyle.Danger);
    
        const mute = new ButtonBuilder()
            .setCustomId('mute')
            .setLabel('Выдать мут')
            .setStyle(ButtonStyle.Secondary);
    
        const kick = new ButtonBuilder()
            .setCustomId('kick')
            .setLabel('Кикнуть с сервера')
            .setStyle(ButtonStyle.Secondary);
    
        const row = new ActionRowBuilder()
            .addComponents(ban, mute, kick);
    
        await interaction.reply({
            embeds: [
                new EmbedBuilder()
                    .setColor(Blue)
                    .setAuthor({ name: `Действие с ${target.displayName}`, iconURL: interaction.member.displayAvatarURL({ dynamic: true }), url: 'https://discord.js.org' })
            ],
            components: [row],
        });
    
        const collector = interaction.channel.createMessageComponentCollector({ time: 10000 }); // Установите нужное время для коллектора
    
        collector.on('collect', async (i) => {
            if (i.customId === 'ban') {
                await target.ban({ reason: reason });
                await interaction.followUp(`Пользователь ${target} был забанен по причине: ${reason}`);
            }
        });
    },
    

    }; const collector = interaction.channel.createMessageComponentCollector({ time: 10000 }); // Установите нужное время для коллектора

        collector.on('collect', async (i) => {
            if (i.customId === 'kick') {
                await member.kick();
                await interaction.followUp(`Пользователь ${target} был кикнут по причине: ${reason}`);
            }
        });
    },
    

    };

  2. Assistant

    Причина возникновения ошибки заключается в том, что после метода addUserOption у вас стоит точка, что некорректно. Ошибка здесь:

    .addUserOption(option =>
        option
            .setName('member')
            .setDescription('пользователь для взаимодействия')
            .setRequired(true)),
    
    .addStringOption(option =>
    

    Чтобы исправить эту ошибку, удалите запятую после setRequired(true)) и перенесите точку в начало следующего метода. Измененный код будет выглядеть так:

    const { ActionRowBuilder, ButtonBuilder, ButtonStyle, SlashCommandBuilder, EmbedBuilder } = require('discord.js');
    
    module.exports = {
        data: new SlashCommandBuilder()
            .setName('action')
            .setDescription('Взаимодействовать с участником')
            .addUserOption(option =>
                option
                    .setName('member')
                    .setDescription('пользователь для взаимодействия')
                    .setRequired(true))
            .addStringOption(option =>
                option
                    .setName('reason')
                    .setDescription('Причина')
                    .setRequired(false)),
        async execute(interaction) {
            const target = interaction.options.getMember('member');
            const reason = 'Причина'; // Замените на вашу логику для получения причины
    
            const ban = new ButtonBuilder()
                .setCustomId('ban')
                .setLabel('Выдать бан')
                .setStyle(ButtonStyle.Danger);
    
            const mute = new ButtonBuilder()
                .setCustomId('mute')
                .setLabel('Выдать мут')
                .setStyle(ButtonStyle.Secondary);
    
            const kick = new ButtonBuilder()
                .setCustomId('kick')
                .setLabel('Кикнуть с сервера')
                .setStyle(ButtonStyle.Secondary);
    
            const row = new ActionRowBuilder()
                .addComponents(ban, mute, kick);
    
            await interaction.reply({
                embeds: [
                    new EmbedBuilder()
                        .setColor(Blue)
                        .setAuthor({ name: `Действие с ${target.displayName}`, iconURL: interaction.member.displayAvatarURL({ dynamic: true }), url: 'https://discord.js.org' })
                ],
                components: [row],
            });
    
            const collector = interaction.channel.createMessageComponentCollector({ time: 10000 }); // Установите нужное время для коллектора
    
            collector.on('collect', async (i) => {
                if (i.customId === 'ban') {
                    await target.ban({ reason: reason });
                    await interaction.followUp(`Пользователь ${target} был забанен по причине: ${reason}`);
                }
            });
        },
    };
    

    После внесения изменений, ошибка больше не должна возникать.