Top.Mail.Ru
Ответы
Аватар пользователя
Аватар пользователя
Аватар пользователя
Аватар пользователя
Программирование
+3

Oшибка: ReferenceError: client is not defined

1234567891011121314151617181920212223242526272829
 const { ActionRowBuilder, Events, ModalBuilder, TextInputBuilder, TextInputStyle } = require('discord.js');

client.on(Events.InteractionCreate, async interaction => {
	if (!interaction.isChatInputCommand()) return;

	if (interaction.commandName === 'ping') {
		const modal = new ModalBuilder()
			.setCustomId('myModal')
			.setTitle('My Modal');


		const favoriteColorInput = new TextInputBuilder()
			.setCustomId('favoriteColorInput')
			.setLabel("What's your favorite color?")
			.setStyle(TextInputStyle.Short);

		const hobbiesInput = new TextInputBuilder()
			.setCustomId('hobbiesInput')
			.setLabel("What's some of your favorite hobbies?")
			.setStyle(TextInputStyle.Paragraph);

		const firstActionRow = new ActionRowBuilder().addComponents(favoriteColorInput);
		const secondActionRow = new ActionRowBuilder().addComponents(hobbiesInput);

		modal.addComponents(firstActionRow, secondActionRow);

		await interaction.showModal(modal);
	}
}); 

Что делать если вылазит ошибка ReferenceError: client is not defined

По дате
По рейтингу
Аватар пользователя
Просветленный

Скажу честно. Если ты действительно задаёшься этим вопросом, то тебе надо немного притормозить с Discord.js и вернутся к просто js. Потому что данный вопрос говорить о том что ты не понимаешь зачем вообще нужна самая первая строка в коде и ты не умеешь интерпретировать текст ошибки или не знаешь английский/не знаешь как пользоваться онлайн переводчиком.

Любую переменную надо инициализировать перед тем как её использовать. 1. строка какраз для этого. Объекта client в ней нет.