KIRIK12
@KIRIK12

Выдает ошибку setRequired is not a function, в документации функция есть, почему?

Код
const Discord = require('discord.js');
const { SlashCommandBuilder } = require('@discordjs/builders');

module.exports = {
	data: new SlashCommandBuilder()
		.setName('ban')
		.setDescription('Отправляет ваш аватар/аватар упомянутого пользователя')
		.addUserOption(option => option
			.setName('banuser')
			.setDescription('Выберите пользователя'))
			.setRequired(true)
		.addNumberOption(option => option
			.setName('days')
			.setDescription('Количество дней бана, от 0 до 7'))
		.addStringOption(option => option
			.setName('reason')
			.setDescription('Укажите причину'))
			.setRequired(true),
	async execute(interaction) {
		let bUser = interaction.options.getMember('banuser')
		let reason = interaction.options.getString('reason')
		let days = interaction.options.getNumber('days')

        if(!bUser) return interaction.reply({content: 'Укажите пользователя, которого вы хотите забанить!', ephemeral: true})

		if(bUser.id === interaction.user.id) interaction.reply({content: "Вы не можете забанить самого себя!", ephemeral: true}); 

		if (!interaction.guild.me.permissions.has("BAN_MEMBERS")) return interaction.reply({content: "У меня нет прав!", ephemeral: true})
		if (!interaction.member.permissions.has("BAN_MEMBERS")) return interaction.reply({content: "У вас нет прав!", ephemeral: true})

		if (!reason) return interaction.reply({content: "Вы не указали причину!", ephemeral: true})
		if (!days) days = 0

		bUser.ban({reason: reason, days: days})

		const ban_embed = new Discord.MessageEmbed()
     	.setColor('#db0f0f')
     	.addFields(
         	{ name: 'Пользователь', value: `<@${interaction.user.id}>` },
         	{ name: 'Забанил', value: `<@${bUser.id}>` },
         	{ name: 'По причине', value: reason }
		);

		interaction.reply({embeds: [ban_embed]})
	},
};

казалось бы, метод в документации есть, с другими методами проблем нет, но вылезает
ошибка
TypeError: (intermediate value).setName(...).setDescription(...).addUserOption(...).setRequired is not a function
    at Object.<anonymous> (C:\Users\*\OneDrive\Документы\discord-bots\banette-bot\commands\ban.js:11:5)     
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\*\OneDrive\Документы\discord-bots\banette-bot\index.js:14:18)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
  • Вопрос задан
  • 105 просмотров
Решения вопроса 2
Immortal_pony
@Immortal_pony
setDescription('Выберите пользователя')) - вы тут лишнюю скобку закрыли
Ответ написан
@rzvr
.setName('ban')
    .setDescription('Отправляет ваш аватар/аватар упомянутого пользователя')
    .addUserOption(option => option
      .setName('banuser')
      .setRequired(true)
      .setDescription('Выберите пользователя'))
    .addNumberOption(option => option
      .setName('days')
      .setDescription('Количество дней бана, от 0 до 7'))
    .addStringOption(option => option
      .setName('reason')
      .setRequired(true)
      .setDescription('Укажите причину')),
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы